import { type Auth, type Unsubscribe, type User } from 'firebase/auth'; import { type ReactiveController, type ReactiveControllerHost } from 'lit'; export type AuthTarget = Auth | (() => Auth | null | undefined) | null | undefined; export interface AuthControllerOptions { /** * Firebase Auth instance or a dynamic getter returning one (or null/undefined). */ auth?: AuthTarget; /** * Whether to automatically fetch custom claims via `user.getIdTokenResult()`. * Default: `true`. */ loadClaims?: boolean; /** * Whether to force refresh the ID token when extracting claims. * Default: `false`. */ forceRefreshClaims?: boolean; /** * Callback invoked whenever authentication state or claims change. */ onAuthStateChanged?: (user: User | null, claims: Record) => void; /** * Callback invoked on auth errors. */ onError?: (error: Error) => void; } /** * A Lit Reactive Controller that manages reactive Firebase Authentication state. * * Automatically tracks `user`, ID token claims, and authentication loading state * across component lifecycles using `onIdTokenChanged`. * * @example * ```typescript * class UserProfileElement extends LitElement { * private authCtrl = new AuthController(this, { auth }); * * render() { * if (this.authCtrl.loading) return html`

Authenticating...

`; * if (!this.authCtrl.isLoggedIn) return html`

Please log in.

`; * * return html` *

Welcome, ${this.authCtrl.displayName}

* ${this.authCtrl.hasClaim('admin') ? html`Admin` : ''} * `; * } * } * ``` */ export declare class AuthController implements ReactiveController { protected host: ReactiveControllerHost; protected options: AuthControllerOptions; protected authTarget: AuthTarget; protected activeAuth: Auth | null; protected unsubscribeFn?: Unsubscribe; protected isHostConnected: boolean; /** * The currently signed-in Firebase User, or `null` if unauthenticated. */ user: User | null; /** * Custom claims extracted from the user's ID token. */ claims: Record; /** * Whether the controller is waiting for initial authentication resolution. */ loading: boolean; /** * Any error that occurred during authentication or claims resolution. */ error?: Error; constructor(host: ReactiveControllerHost, options?: AuthControllerOptions); /** * Whether a user is currently signed in. */ get isLoggedIn(): boolean; /** * Unique ID of the authenticated user. */ get uid(): string | undefined; /** * Email address of the authenticated user. */ get email(): string | undefined; /** * Display name of the authenticated user. */ get displayName(): string | undefined; /** * Profile photo URL of the authenticated user. */ get photoURL(): string | undefined; /** * Lifecycle callback: host connected to DOM. */ hostConnected(): void; /** * Lifecycle callback: host disconnected from DOM. */ hostDisconnected(): void; /** * Checks whether the user holds a specific custom claim. * * @param claim The claim name (e.g. `'admin'`). * @param expectedValue Optional specific value to match. If omitted, checks for truthiness. */ hasClaim(claim: string, expectedValue?: any): boolean; /** * Re-fetches the ID token result and refreshes user claims. * * @param forceRefresh Whether to force a token refresh. Defaults to `true`. */ refreshClaims(forceRefresh?: boolean): Promise>; /** * Signs out the current user. */ signOut(): Promise; /** * Begins listening to authentication changes on the configured Auth instance. */ subscribe(): void; /** * Unsubscribes from active auth listener. */ unsubscribe(): void; protected resolveAuth(): Auth | null; } //# sourceMappingURL=auth.controller.d.ts.map