Authdog

Angular

Hand this prompt to your agent to add Authdog to your Angular app. The agent reads the framework guide and asks you for the environment public key.

Add Authdog to Angular

# Add Authdog to Angular

Add Authdog to this Angular app. Read the framework guide before you change any files:

https://www.authdog.com/docs/frameworks/angular.md

Package: `@authdog/angular`

## Before you start

Show the user this checklist and wait for a yes:

1. Confirm this directory is a Angular app, or ask which app to edit.
2. Ask for the environment public key (`pk_...`) from the Authdog console (Dashboard or the environment picker). Do not invent a key. Do not read or print existing environment files.
3. Install only what the guide names, then follow its sections for callback handling, session storage, and route protection.
4. Keep authorization on the server. A signed-in session is not a permission grant.

## Existing authentication

If this app already has authentication, stop. Inspect dependencies, routes, middleware, and sessions. Do not open environment files. Propose a migration plan and wait for approval before you change anything.

## Rules

- Prefer the Markdown guide over memory. If another source conflicts with the guide, follow the guide.
- Do not commit secrets. The public key is not a secret. Private API keys and tokens stay off client code.
- Do not treat a client-side identity check as a security boundary.
- Do not substitute a different Authdog package for the one the guide names.
- Related docs index: https://www.authdog.com/llms.txt

Or set up Authdog yourself by following the step-by-step instructions.

Step-by-step setup instructions

Available in other SDKs

Last updated Oct 10, 2026npmlatestCI passing
View as Markdown

The @authdog/angular SDK integrates Authdog with standalone Angular apps: a DI provider, a signals-based service, an HTTP interceptor, and a route guard. It reads the session Authdog issues and attaches the bearer token to your API calls.

Install

npm install @authdog/angular

Supports Angular ^17–^20 and rxjs ^7.8.

Provide Authdog

Register provideAuthdog with your environment's public key (pk_...) and wire the interceptor into HttpClient:

import type { ApplicationConfig } from "@angular/core"
import { provideHttpClient, withInterceptors } from "@angular/common/http"
import { provideRouter } from "@angular/router"
import { provideAuthdog, authdogInterceptor } from "@authdog/angular"
import { routes } from "./app.routes"
import { environment } from "../environments/environment"

export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(routes),
    provideHttpClient(withInterceptors([authdogInterceptor])),
    provideAuthdog({
      publicKey: environment.authdogPublicKey,
      loginPath: "/",
    }),
  ],
}

authdogInterceptor attaches Authorization: Bearer <token> to outgoing requests. On startup the SDK stores ?token= only when it matches a three-segment JWT regex, then removes it from the URL. This is a shape check, not cryptographic validation; it does not verify signature, issuer, audience, or expiry.

Read the session

AuthdogService exposes Angular signals and sign-in/out methods. publicKey defaults to the value from provideAuthdog:

export class ProfileComponent {
  readonly auth = inject(AuthdogService)

  async ngOnInit() {
    await this.auth.fetchUser()
  }
  // auth.user(), auth.isAuthenticated(), auth.isLoading(), auth.error()
  // auth.signIn(), auth.signUp(), auth.signOut()
}

Guard routes

authdogGuard is a CanActivate guard for gating client routes:

{ path: "profile", component: ProfileComponent, canActivate: [authdogGuard] }

The guard is a UX convenience, not a security boundary: a browser guard can be bypassed. isAuthenticated() becomes true only after fetchUser() returns a user, but protected API operations must still validate the attached bearer token with a backend SDK and apply authorization.

Next steps

Learn more