/** * P1AuthProvider * * Reusable auth context for any React app integrating with P1. * Supports two auth modes: 'mock' and 'broker'. * Handles token lifecycle, validation, and expiry across all modes. * * Framework-agnostic within React — works with Next.js, Remix, Vite, CRA, etc. */ import React from 'react'; import type { LogoutOutcome } from './logout.js'; import { P1_LOGGED_IN_KEY } from './storage-keys.js'; export type AuthMode = 'mock' | 'broker'; export interface AuthUser { id: string; name: string; email?: string; picture?: string; } export interface P1AuthContextValue { isAuthenticated: boolean; isLoading: boolean; user: AuthUser | null; token: string | null; error: string | null; authMode: AuthMode; isSessionExpired: boolean; login(userId?: string): Promise; /** * Returns the outcome rather than throwing. `error` means the credential was * deliberately kept and the user is still signed in, so the caller has to say * so — `error` on this context is the login slot and is not set here. */ logout(): Promise; getToken: () => Promise; } /** * @internal Local-development only. These fixed UUIDs are only recognised by * the backend when `ENVIRONMENT === 'local'`. */ export declare const DEMO_USERS: { id: string; name: string; }[]; export { P1_LOGGED_IN_KEY }; export interface P1AuthProviderProps { /** Auth mode: 'mock' for demo users, 'broker' for auth broker. */ authMode: AuthMode; /** P1 backend base URL (e.g., "http://localhost:8787"). */ p1BaseUrl: string; /** localStorage key for token persistence. Default: 'p1_auth_token'. */ tokenStorageKey?: string; children: React.ReactNode; } export declare function P1AuthProvider(props: P1AuthProviderProps): React.ReactElement; /** * Hook to access the P1 auth context. * Must be used within a P1AuthProvider. */ export declare function useP1Auth(): P1AuthContextValue; /** * Like useP1Auth but returns null when used outside a P1AuthProvider. * Use this in internal components that need to subscribe to auth state * but may be rendered in contexts where the provider is absent. */ export declare function useOptionalP1Auth(): P1AuthContextValue | null;