@civic/auth 0.11.2 → 0.11.3-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/nextjs/NextClientAuthenticationRefresher.d.ts +8 -0
- package/dist/nextjs/NextClientAuthenticationRefresher.d.ts.map +1 -0
- package/dist/nextjs/NextClientAuthenticationRefresher.js +24 -0
- package/dist/nextjs/NextClientAuthenticationRefresher.js.map +1 -0
- package/dist/nextjs/NextServerAuthenticationRefresherImpl.d.ts +12 -0
- package/dist/nextjs/NextServerAuthenticationRefresherImpl.d.ts.map +1 -0
- package/dist/nextjs/NextServerAuthenticationRefresherImpl.js +25 -0
- package/dist/nextjs/NextServerAuthenticationRefresherImpl.js.map +1 -0
- package/dist/nextjs/hooks/useRefresh.d.ts +5 -0
- package/dist/nextjs/hooks/useRefresh.d.ts.map +1 -0
- package/dist/nextjs/hooks/useRefresh.js +57 -0
- package/dist/nextjs/hooks/useRefresh.js.map +1 -0
- package/dist/nextjs/providers/NextAuthProvider.d.ts +1 -1
- package/dist/nextjs/providers/NextAuthProvider.d.ts.map +1 -1
- package/dist/nextjs/providers/NextAuthProvider.js.map +1 -1
- package/dist/nextjs/providers/NextAuthProviderClient.d.ts.map +1 -1
- package/dist/nextjs/providers/NextAuthProviderClient.js +2 -3
- package/dist/nextjs/providers/NextAuthProviderClient.js.map +1 -1
- package/dist/react-router-7/auth-loader.d.ts +18 -0
- package/dist/react-router-7/auth-loader.d.ts.map +1 -0
- package/dist/react-router-7/auth-loader.js +36 -0
- package/dist/react-router-7/auth-loader.js.map +1 -0
- package/dist/reactjs/core/GlobalAuthManager.d.ts.map +1 -1
- package/dist/reactjs/core/GlobalAuthManager.js +18 -0
- package/dist/reactjs/core/GlobalAuthManager.js.map +1 -1
- package/dist/reactjs/providers/CivicAuthContext.d.ts +44 -0
- package/dist/reactjs/providers/CivicAuthContext.d.ts.map +1 -0
- package/dist/reactjs/providers/CivicAuthContext.js +313 -0
- package/dist/reactjs/providers/CivicAuthContext.js.map +1 -0
- package/dist/reactjs/providers/index.d.ts +0 -3
- package/dist/reactjs/providers/index.d.ts.map +1 -1
- package/dist/reactjs/providers/index.js +0 -4
- package/dist/reactjs/providers/index.js.map +1 -1
- package/dist/shared/hooks/index.d.ts +0 -7
- package/dist/shared/hooks/index.d.ts.map +1 -1
- package/dist/shared/hooks/index.js +0 -7
- package/dist/shared/hooks/index.js.map +1 -1
- package/dist/shared/hooks/useRefresh.d.ts +6 -0
- package/dist/shared/hooks/useRefresh.d.ts.map +1 -0
- package/dist/shared/hooks/useRefresh.js +47 -0
- package/dist/shared/hooks/useRefresh.js.map +1 -0
- package/dist/shared/version.d.ts +1 -1
- package/dist/shared/version.d.ts.map +1 -1
- package/dist/shared/version.js +1 -1
- package/dist/shared/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/vanillajs/auth/CivicAuth.d.ts.map +1 -1
- package/dist/vanillajs/auth/CivicAuth.js +4 -0
- package/dist/vanillajs/auth/CivicAuth.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalAuthManager.js","sourceRoot":"","sources":["../../../src/reactjs/core/GlobalAuthManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,SAAS,GACV,MAAM,0BAA0B,CAAC;AAWlC,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AA2DvF;;;GAGG;AACH,MAAM,iBAAiB;IACb,MAAM,CAAC,QAAQ,GAA6B,IAAI,CAAC;IACjD,IAAI,GAAqB,IAAI,CAAC;IAC9B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I,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACtE,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED;;OAEG;IACK,QAAQ,CAAC,OAAiC;QAChD,IAAI,CAAC,KAAK,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC;QAC3C,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAO;QAClB,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACnB,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAAC,4CAA4C;IACjF,CAAC;;AAGH,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["/**\n * GlobalAuthManager - Singleton Authentication State Manager\n *\n * This module provides a global singleton that manages authentication state across a React application\n * without requiring React Context providers or prop drilling. It acts as a centralized authentication\n * manager that wraps the CivicAuth vanilla JavaScript library and provides a React-friendly interface.\n *\n * Key Features:\n * - Singleton pattern ensures single auth instance across the entire app\n * - Eliminates need for React Context providers and reduces bundle size\n * - Manages authentication state (user, session, loading, errors)\n * - Handles sign-in/sign-out flows with event-driven updates\n * - Provides idempotent initialization (safe to call multiple times)\n * - Supports multiple React hooks subscribing to the same auth state\n * - Automatic session refresh and user data synchronization\n *\n * Usage:\n * - Initialize once in your app with authentication configuration\n * - Use React hooks (useCivicAuth, useAuth, etc.) to access auth state\n * - The manager handles all underlying CivicAuth SDK interactions\n * - State updates are automatically propagated to all subscribed components\n *\n * This design pattern is particularly useful for:\n * - Large applications with many components needing auth state\n * - Avoiding provider wrapper hell in React component trees\n * - Ensuring consistent auth state across disconnected component hierarchies\n * - Server-side rendering scenarios where providers might be problematic\n */\n\nimport {\n CivicAuth,\n AuthenticationEvents,\n AuthEvent,\n} from \"../../vanillajs/index.js\";\nimport type {\n User,\n Session,\n CivicAuthClientConfig,\n OnSignInResponse,\n OnSignOutResponse,\n} from \"../../vanillajs/index.js\";\nimport type { AuthStorage, FrameworkType } from \"../../types.js\";\nimport type { VanillaJSDisplayMode } from \"../../vanillajs/auth/types/AuthTypes.js\";\nimport type { LoggingConfig } from \"@/vanillajs/auth/types/AuthTypes.js\";\nimport { DEFAULT_AUTH_PROCESS_TIMEOUT } from \"../../vanillajs/auth/types/AuthTypes.js\";\nimport type { BackendEndpoints } from \"@/server/config.js\";\n\n// Event payload interfaces\ninterface SignInErrorEvent {\n detail: string;\n}\n\nexport interface GlobalAuthConfig {\n clientId?: string;\n redirectUrl?: string;\n loginUrl?: string;\n config?: {\n oauthServer?: string;\n };\n displayMode?: VanillaJSDisplayMode;\n iframeMode?: \"modal\" | \"embedded\";\n nonce?: string;\n logoutRedirectUrl?: string;\n scopes?: string[];\n authProcessTimeout?: number;\n onRefresh?: (error?: Error) => void;\n onSignIn?: (response: OnSignInResponse) => void | Promise<void>;\n onSignOut?: (response: OnSignOutResponse) => void | Promise<void>;\n onPreSignIn?: (response: OnSignInResponse) => Promise<void>;\n onPreSignOut?: (response: OnSignOutResponse) => Promise<void>;\n onUrlChange?: (url: string, source?: string) => void;\n logging?: LoggingConfig;\n preloadIframe?: boolean;\n autoRedirect?: boolean;\n /** Framework being used (for analytics) - internal use only */\n framework?: FrameworkType;\n backendEndpoints?: BackendEndpoints;\n targetContainerElement?: HTMLElement | string;\n loginSuccessUrl?: string;\n storage?: AuthStorage;\n initialUser?: User | null;\n disableRefresh?: boolean;\n}\n\nexport type AuthStatus =\n | \"authenticated\"\n | \"unauthenticated\"\n | \"authenticating\"\n | \"error\"\n | \"signing_out\";\n\nexport interface GlobalAuthState {\n user: User | null;\n session: Session | null;\n isLoading: boolean;\n authStatus: AuthStatus;\n error: Error | null;\n displayMode?: VanillaJSDisplayMode;\n isPreloaded?: boolean;\n}\n\ntype StateListener = (state: GlobalAuthState) => void;\n\n/**\n * Global singleton that manages CivicAuth instance for React hooks\n * Eliminates the need for React providers\n */\nclass GlobalAuthManager {\n private static instance: GlobalAuthManager | null = null;\n private auth: CivicAuth | null = null;\n private events: AuthenticationEvents | null = null;\n private config: GlobalAuthConfig | null = null;\n private listeners = new Set<StateListener>();\n private callbacks: {\n onSignIn?: (response: OnSignInResponse) => void | Promise<void>;\n onSignOut?: (response: OnSignOutResponse) => void | Promise<void>;\n onUrlChange?: (url: string, source?: string) => void;\n onRefresh?: (error?: Error) => void;\n onPreSignIn?: (response: OnSignInResponse) => void | Promise<void>;\n onPreSignOut?: (response: OnSignOutResponse) => void | Promise<void>;\n } = {};\n private initializationPromise: Promise<void> | null = null;\n\n private state: GlobalAuthState = {\n user: null,\n session: null,\n isLoading: false,\n authStatus: \"unauthenticated\",\n error: null,\n displayMode: undefined,\n };\n\n private constructor() {\n // Private constructor for singleton\n }\n\n static getInstance(): GlobalAuthManager {\n if (!GlobalAuthManager.instance) {\n GlobalAuthManager.instance = new GlobalAuthManager();\n }\n return GlobalAuthManager.instance;\n }\n\n /**\n * Initialize auth with config (idempotent)\n * Returns the same promise for concurrent calls with same config\n */\n async initialize(config: GlobalAuthConfig): Promise<void> {\n // If we have a promise and same config, return existing promise\n if (\n this.initializationPromise &&\n this.config &&\n this.isSameConfig(config)\n ) {\n return this.initializationPromise;\n }\n\n // If different config, reset everything\n if (this.config && !this.isSameConfig(config)) {\n this.initializationPromise = null;\n await this.cleanup();\n }\n\n // Create new initialization promise if needed\n if (!this.initializationPromise) {\n this.initializationPromise = this._doInitialize(config);\n }\n\n return this.initializationPromise;\n }\n\n private defaultOnUrlChange(url: string, source?: string) {\n console.log(\"onUrlChange triggering window redirect\", { url, source });\n window.location.href = url;\n }\n\n public updateCallbacks(callbacks: {\n onSignIn?: (response: OnSignInResponse) => void | Promise<void>;\n onSignOut?: (response: OnSignOutResponse) => void | Promise<void>;\n onUrlChange?: (url: string, source?: string) => void;\n onRefresh?: (error?: Error) => void;\n onPreSignIn?: (response: OnSignInResponse) => void | Promise<void>;\n onPreSignOut?: (response: OnSignOutResponse) => void | Promise<void>;\n }): void {\n this.callbacks = {\n ...this.callbacks,\n ...callbacks,\n };\n }\n /**\n * Private method that does the actual initialization work\n */\n private async _doInitialize(config: GlobalAuthConfig): Promise<void> {\n this.config = config;\n this.callbacks = {\n onSignIn: config.onSignIn,\n onSignOut: config.onSignOut,\n onUrlChange: config.onUrlChange || this.defaultOnUrlChange,\n onRefresh: config.onRefresh,\n onPreSignIn: config.onPreSignIn || this.callbacks.onPreSignIn,\n onPreSignOut: config.onPreSignOut || this.callbacks.onPreSignOut,\n };\n this.setState({\n isLoading: true,\n error: null,\n ...(this.config.initialUser && this.state.authStatus !== \"signing_out\"\n ? { user: this.config.initialUser, authStatus: \"authenticated\" }\n : {}), // Set initial user if provided\n });\n\n try {\n this.events = new AuthenticationEvents();\n this.setupEventListeners();\n\n // Build base config common to both branches\n const baseConfig = {\n ...config,\n oauthServerBaseUrl: config.config?.oauthServer,\n scopes: config.scopes || [\n \"openid\",\n \"profile\",\n \"email\",\n \"offline_access\",\n ],\n displayMode: config.displayMode || \"iframe\",\n iframeDisplayMode: config.iframeMode || \"modal\",\n nonce: config.nonce,\n authProcessTimeout:\n config.authProcessTimeout || DEFAULT_AUTH_PROCESS_TIMEOUT,\n preloadIframe: config.preloadIframe,\n autoRedirect: config.autoRedirect,\n events: this.events,\n framework: config.framework,\n storageAdapter: config.storage,\n };\n\n // Build auth config based on discriminated union requirements\n const authConfig: CivicAuthClientConfig = config.loginUrl\n ? {\n // Backend integration mode: loginUrl required, clientId optional\n ...baseConfig,\n loginUrl: config.loginUrl,\n clientId: config.clientId,\n }\n : {\n // Standard OAuth mode: clientId required, loginUrl optional\n ...baseConfig,\n clientId: config.clientId!,\n loginUrl: config.loginUrl,\n };\n\n // Only add redirectUrl if provided\n if (config.redirectUrl) {\n authConfig.redirectUrl = config.redirectUrl;\n }\n\n // Only add logoutRedirectUrl if provided\n if (config.logoutRedirectUrl) {\n authConfig.logoutRedirectUrl = config.logoutRedirectUrl;\n }\n\n // Only add loginSuccessUrl if provided\n if (config.loginSuccessUrl) {\n authConfig.loginSuccessUrl = config.loginSuccessUrl;\n }\n\n this.auth = await CivicAuth.create(authConfig);\n // Check initial auth state\n const isAuthenticated = await this.auth.isAuthenticated();\n\n if (isAuthenticated) {\n await this.updateUserAndSession();\n this.setState({ authStatus: \"authenticated\" });\n } else {\n this.setState({ authStatus: \"unauthenticated\" });\n\n // Note: Preloading is now handled automatically by CivicAuth based on config.preloadIframe\n }\n\n this.setState({\n isLoading: false,\n displayMode: config.displayMode,\n });\n } catch (error) {\n // Reset promise on error so it can be retried\n this.initializationPromise = null;\n\n const authError =\n error instanceof Error\n ? error\n : new Error(\"Auth initialization failed\");\n this.setState({\n error: authError,\n authStatus: \"error\",\n isLoading: false,\n });\n throw authError;\n }\n }\n\n /**\n * Subscribe to state changes\n */\n subscribe(listener: StateListener): () => void {\n this.listeners.add(listener);\n return () => this.listeners.delete(listener);\n }\n\n /**\n * Get current state\n */\n getState(): GlobalAuthState {\n return { ...this.state };\n }\n\n /**\n * Get current configuration\n * Returns the current config or null if not initialized\n */\n getConfig(): GlobalAuthConfig | null {\n return this.config ? { ...this.config } : null;\n }\n\n /**\n * Sign in\n */\n async signIn(): Promise<{ user: User }> {\n if (!this.auth) {\n throw new Error(\"Auth not initialized\");\n }\n\n const authResult = await this.auth.startAuthentication();\n\n // If authentication returned a user, use it directly\n if (authResult.user) {\n this.setState({\n user: authResult.user,\n authStatus: \"authenticated\",\n error: null,\n });\n return { user: authResult.user };\n }\n\n // Fallback: try to refresh user and session data\n await this.updateUserAndSession();\n\n // Check the current state for the user after refresh\n const currentState = this.getState();\n\n if (!currentState.user) {\n throw new Error(\"Authentication succeeded but no user was returned\");\n }\n\n // Return the user object from current state\n return { user: currentState.user };\n }\n\n /**\n * Sign out\n */\n async signOut(): Promise<void> {\n if (!this.auth) {\n throw new Error(\"Auth not initialized\");\n }\n if (this.state.authStatus === \"unauthenticated\") {\n // Already signed out, no-op\n return;\n }\n await this.auth.logout();\n this.setState({\n user: null,\n session: null,\n authStatus: \"unauthenticated\",\n });\n }\n\n /**\n * Check if authentication is preloaded and ready for instant sign-in\n * @returns True if an iframe is preloaded and ready\n */\n isAuthenticationPreloaded(): boolean {\n return this.auth?.isAuthenticationPreloaded() ?? false;\n }\n\n /**\n * Enable or disable iframe preloading\n */\n setPreloadEnabled(enabled: boolean): void {\n if (!this.auth) {\n throw new Error(\"Auth not initialized\");\n }\n this.auth.setPreloadEnabled(enabled);\n }\n\n /**\n * Check if iframe preloading is enabled\n */\n getPreloadEnabled(): boolean {\n return this.auth?.getPreloadEnabled() ?? true;\n }\n\n /**\n * Reloads embedded authentication interface\n *\n * This method is specifically designed for embedded mode scenarios where the iframe\n * needs to be recreated after navigation or DOM changes. It delegates to the\n * underlying CivicAuth instance's reloadEmbedded method.\n *\n * @returns Promise that resolves when the embedded iframe is created\n * @throws {Error} If not in embedded mode or if auth is not initialized\n */\n async reloadEmbedded(): Promise<void> {\n if (!this.auth) {\n throw new Error(\"Auth not initialized. Call initialize() first.\");\n }\n\n return this.auth.reloadEmbedded();\n }\n\n /**\n * Reset authentication state when detected from back-forward cache (bfcache)\n * This fixes issues where sign-in button becomes unclickable after back navigation\n */\n resetOnBfcache(): void {\n if (!this.auth) return;\n\n // Reset internal CivicAuth state first\n this.auth.resetOnBfcache();\n\n // Reset auth state to unauthenticated to allow new sign-in attempts\n this.setState({\n authStatus: \"unauthenticated\",\n isLoading: false,\n error: null,\n user: null,\n session: null,\n });\n\n // Ensure iframe preloading state is refreshed if needed\n if (this.getPreloadEnabled()) {\n this.auth.setPreloadEnabled(true);\n }\n }\n\n /**\n * Check if config is the same (for idempotent initialization)\n */\n private isSameConfig(newConfig: GlobalAuthConfig): boolean {\n if (!this.config) return false;\n return (\n this.config.clientId === newConfig.clientId &&\n this.config.config?.oauthServer === newConfig.config?.oauthServer &&\n this.config.displayMode === newConfig.displayMode &&\n this.config.nonce === newConfig.nonce &&\n this.config.preloadIframe === newConfig.preloadIframe &&\n this.config.autoRedirect === newConfig.autoRedirect &&\n this.config?.onSignIn === newConfig?.onSignIn &&\n this.config?.onSignOut === newConfig?.onSignOut &&\n this.config?.onUrlChange === newConfig?.onUrlChange\n );\n }\n\n /**\n * Setup event listeners for auth state changes\n */\n private setupEventListeners(): void {\n if (!this.events) return;\n\n this.events.on(AuthEvent.SIGN_IN_STARTED, () => {\n this.setState({\n isLoading: true,\n authStatus: \"authenticating\",\n error: null,\n });\n });\n\n this.events.on(AuthEvent.TOKEN_REFRESH_COMPLETE, () => {\n this.setState({\n isLoading: false,\n authStatus: \"authenticated\",\n });\n this.updateUserAndSession();\n this.callbacks.onRefresh?.();\n });\n\n this.events.on(AuthEvent.SIGN_IN_COMPLETE, async () => {\n this.setState({\n isLoading: false,\n authStatus: \"authenticated\",\n error: null,\n });\n this.updateUserAndSession();\n await this.callbacks.onPreSignIn?.({\n user: this.state.user,\n session: this.state.session,\n });\n await this.callbacks.onSignIn?.({\n user: this.state.user,\n session: this.state.session,\n });\n });\n\n this.events.on(\n AuthEvent.SIGN_IN_ERROR,\n async (event?: SignInErrorEvent) => {\n const errorDetail = event?.detail || \"Authentication failed\";\n const authError = new Error(errorDetail);\n this.setState({\n isLoading: false,\n authStatus: \"error\",\n error: authError,\n });\n await this.callbacks.onPreSignIn?.({\n error: authError,\n });\n await this.callbacks.onSignIn?.({ error: authError });\n },\n );\n\n this.events.on(AuthEvent.SIGN_OUT_STARTED, () => {\n this.setState({\n isLoading: true,\n authStatus: \"signing_out\",\n error: null,\n });\n });\n\n this.events.on(AuthEvent.SIGN_OUT_COMPLETE, async () => {\n this.setState({\n isLoading: false,\n authStatus: \"unauthenticated\",\n user: null,\n session: null,\n error: null,\n });\n await this.callbacks.onPreSignOut?.({});\n await this.callbacks.onSignOut?.({});\n });\n\n this.events.on(AuthEvent.SIGN_OUT_ERROR, async (error?: Error) => {\n const signOutError =\n error instanceof Error ? error : new Error(\"Sign-out failed\");\n this.setState({\n isLoading: false,\n authStatus: \"error\",\n error: signOutError,\n });\n await this.callbacks.onPreSignOut?.({ error: signOutError });\n await this.callbacks.onSignOut?.({ error: signOutError });\n });\n\n this.events.on(AuthEvent.USER_SESSION_CHANGED, () => {\n this.updateUserAndSession();\n });\n\n this.events.on(\n AuthEvent.URL_CHANGE,\n (event?: { detail?: string; url?: string; source?: string }) => {\n this.setState({\n authStatus: \"authenticating\", // Keep as authenticating since we're redirecting\n error: null,\n });\n // Call custom URL change handler if provided\n if (event?.url && this.callbacks.onUrlChange) {\n this.callbacks.onUrlChange(event.url, event.source);\n }\n },\n );\n }\n\n /**\n * Refresh user and session data\n */\n private async updateUserAndSession(): Promise<void> {\n if (!this.auth) return;\n\n try {\n const [session, user] = await Promise.all([\n this.auth.getCurrentSession(),\n this.auth.getCurrentUser(),\n ]);\n\n this.setState({ session, user });\n } catch (error) {\n const sessionError =\n error instanceof Error ? error : new Error(\"Failed to get session\");\n this.setState({ error: sessionError });\n }\n }\n\n /**\n * Update state and notify listeners\n */\n private setState(updates: Partial<GlobalAuthState>): void {\n this.state = { ...this.state, ...updates };\n this.listeners.forEach((listener) => listener(this.state));\n }\n\n /**\n * Cleanup auth instance\n */\n public async cleanup(): Promise<void> {\n if (this.auth) {\n await this.auth.destroy();\n this.auth = null;\n }\n this.events = null;\n this.config = null;\n this.initializationPromise = null; // Reset promise for clean re-initialization\n }\n}\n\nexport { GlobalAuthManager };\n"]}
|
|
1
|
+
{"version":3,"file":"GlobalAuthManager.js","sourceRoot":"","sources":["../../../src/reactjs/core/GlobalAuthManager.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E,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED;;OAEG;IACK,QAAQ,CAAC,OAAiC;QAChD,IAAI,CAAC,KAAK,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC;QAC3C,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAO;QAClB,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACnB,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAAC,4CAA4C;IACjF,CAAC;;AAGH,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["/**\n * GlobalAuthManager - Singleton Authentication State Manager\n *\n * This module provides a global singleton that manages authentication state across a React application\n * without requiring React Context providers or prop drilling. It acts as a centralized authentication\n * manager that wraps the CivicAuth vanilla JavaScript library and provides a React-friendly interface.\n *\n * Key Features:\n * - Singleton pattern ensures single auth instance across the entire app\n * - Eliminates need for React Context providers and reduces bundle size\n * - Manages authentication state (user, session, loading, errors)\n * - Handles sign-in/sign-out flows with event-driven updates\n * - Provides idempotent initialization (safe to call multiple times)\n * - Supports multiple React hooks subscribing to the same auth state\n * - Automatic session refresh and user data synchronization\n *\n * Usage:\n * - Initialize once in your app with authentication configuration\n * - Use React hooks (useCivicAuth, useAuth, etc.) to access auth state\n * - The manager handles all underlying CivicAuth SDK interactions\n * - State updates are automatically propagated to all subscribed components\n *\n * This design pattern is particularly useful for:\n * - Large applications with many components needing auth state\n * - Avoiding provider wrapper hell in React component trees\n * - Ensuring consistent auth state across disconnected component hierarchies\n * - Server-side rendering scenarios where providers might be problematic\n */\n\nimport {\n CivicAuth,\n AuthenticationEvents,\n AuthEvent,\n} from \"../../vanillajs/index.js\";\nimport type {\n User,\n Session,\n CivicAuthClientConfig,\n OnSignInResponse,\n OnSignOutResponse,\n} from \"../../vanillajs/index.js\";\nimport type { AuthStorage, FrameworkType } from \"../../types.js\";\nimport type { VanillaJSDisplayMode } from \"../../vanillajs/auth/types/AuthTypes.js\";\nimport type { LoggingConfig } from \"@/vanillajs/auth/types/AuthTypes.js\";\nimport { DEFAULT_AUTH_PROCESS_TIMEOUT } from \"../../vanillajs/auth/types/AuthTypes.js\";\nimport type { BackendEndpoints } from \"@/server/config.js\";\n\n// Event payload interfaces\ninterface SignInErrorEvent {\n detail: string;\n}\n\nexport interface GlobalAuthConfig {\n clientId?: string;\n redirectUrl?: string;\n loginUrl?: string;\n config?: {\n oauthServer?: string;\n };\n displayMode?: VanillaJSDisplayMode;\n iframeMode?: \"modal\" | \"embedded\";\n nonce?: string;\n logoutRedirectUrl?: string;\n scopes?: string[];\n authProcessTimeout?: number;\n onRefresh?: (error?: Error) => void;\n onSignIn?: (response: OnSignInResponse) => void | Promise<void>;\n onSignOut?: (response: OnSignOutResponse) => void | Promise<void>;\n onPreSignIn?: (response: OnSignInResponse) => Promise<void>;\n onPreSignOut?: (response: OnSignOutResponse) => Promise<void>;\n onUrlChange?: (url: string, source?: string) => void;\n logging?: LoggingConfig;\n preloadIframe?: boolean;\n autoRedirect?: boolean;\n /** Framework being used (for analytics) - internal use only */\n framework?: FrameworkType;\n backendEndpoints?: BackendEndpoints;\n targetContainerElement?: HTMLElement | string;\n loginSuccessUrl?: string;\n storage?: AuthStorage;\n initialUser?: User | null;\n disableRefresh?: boolean;\n}\n\nexport type AuthStatus =\n | \"authenticated\"\n | \"unauthenticated\"\n | \"authenticating\"\n | \"error\"\n | \"signing_out\";\n\nexport interface GlobalAuthState {\n user: User | null;\n session: Session | null;\n isLoading: boolean;\n authStatus: AuthStatus;\n error: Error | null;\n displayMode?: VanillaJSDisplayMode;\n isPreloaded?: boolean;\n}\n\ntype StateListener = (state: GlobalAuthState) => void;\n\n/**\n * Global singleton that manages CivicAuth instance for React hooks\n * Eliminates the need for React providers\n */\nclass GlobalAuthManager {\n private static instance: GlobalAuthManager | null = null;\n private auth: CivicAuth | null = null;\n private events: AuthenticationEvents | null = null;\n private config: GlobalAuthConfig | null = null;\n private listeners = new Set<StateListener>();\n private callbacks: {\n onSignIn?: (response: OnSignInResponse) => void | Promise<void>;\n onSignOut?: (response: OnSignOutResponse) => void | Promise<void>;\n onUrlChange?: (url: string, source?: string) => void;\n onRefresh?: (error?: Error) => void;\n onPreSignIn?: (response: OnSignInResponse) => void | Promise<void>;\n onPreSignOut?: (response: OnSignOutResponse) => void | Promise<void>;\n } = {};\n private initializationPromise: Promise<void> | null = null;\n\n private state: GlobalAuthState = {\n user: null,\n session: null,\n isLoading: false,\n authStatus: \"unauthenticated\",\n error: null,\n displayMode: undefined,\n };\n\n private constructor() {\n // Private constructor for singleton\n }\n\n static getInstance(): GlobalAuthManager {\n if (!GlobalAuthManager.instance) {\n GlobalAuthManager.instance = new GlobalAuthManager();\n }\n return GlobalAuthManager.instance;\n }\n\n /**\n * Initialize auth with config (idempotent)\n * Returns the same promise for concurrent calls with same config\n */\n async initialize(config: GlobalAuthConfig): Promise<void> {\n // If we have a promise and same config, return existing promise\n if (\n this.initializationPromise &&\n this.config &&\n this.isSameConfig(config)\n ) {\n return this.initializationPromise;\n }\n\n // If different config, reset everything\n if (this.config && !this.isSameConfig(config)) {\n this.initializationPromise = null;\n await this.cleanup();\n }\n\n // Create new initialization promise if needed\n if (!this.initializationPromise) {\n this.initializationPromise = this._doInitialize(config);\n }\n\n return this.initializationPromise;\n }\n\n private defaultOnUrlChange(url: string, source?: string) {\n console.log(\"onUrlChange triggering window redirect\", { url, source });\n window.location.href = url;\n }\n\n public updateCallbacks(callbacks: {\n onSignIn?: (response: OnSignInResponse) => void | Promise<void>;\n onSignOut?: (response: OnSignOutResponse) => void | Promise<void>;\n onUrlChange?: (url: string, source?: string) => void;\n onRefresh?: (error?: Error) => void;\n onPreSignIn?: (response: OnSignInResponse) => void | Promise<void>;\n onPreSignOut?: (response: OnSignOutResponse) => void | Promise<void>;\n }): void {\n this.callbacks = {\n ...this.callbacks,\n ...callbacks,\n };\n }\n /**\n * Private method that does the actual initialization work\n */\n private async _doInitialize(config: GlobalAuthConfig): Promise<void> {\n this.config = config;\n this.callbacks = {\n onSignIn: config.onSignIn,\n onSignOut: config.onSignOut,\n onUrlChange: config.onUrlChange || this.defaultOnUrlChange,\n onRefresh: config.onRefresh,\n onPreSignIn: config.onPreSignIn || this.callbacks.onPreSignIn,\n onPreSignOut: config.onPreSignOut || this.callbacks.onPreSignOut,\n };\n this.setState({\n isLoading: true,\n error: null,\n ...(this.config.initialUser && this.state.authStatus !== \"signing_out\"\n ? { user: this.config.initialUser, authStatus: \"authenticated\" }\n : {}), // Set initial user if provided\n });\n\n try {\n this.events = new AuthenticationEvents();\n this.setupEventListeners();\n\n // Build base config common to both branches\n const baseConfig = {\n ...config,\n oauthServerBaseUrl: config.config?.oauthServer,\n scopes: config.scopes || [\n \"openid\",\n \"profile\",\n \"email\",\n \"offline_access\",\n ],\n displayMode: config.displayMode || \"iframe\",\n iframeDisplayMode: config.iframeMode || \"modal\",\n nonce: config.nonce,\n authProcessTimeout:\n config.authProcessTimeout || DEFAULT_AUTH_PROCESS_TIMEOUT,\n preloadIframe: config.preloadIframe,\n autoRedirect: config.autoRedirect,\n events: this.events,\n framework: config.framework,\n storageAdapter: config.storage,\n };\n\n // Build auth config based on discriminated union requirements\n const authConfig: CivicAuthClientConfig = config.loginUrl\n ? {\n // Backend integration mode: loginUrl required, clientId optional\n ...baseConfig,\n loginUrl: config.loginUrl,\n clientId: config.clientId,\n }\n : {\n // Standard OAuth mode: clientId required, loginUrl optional\n ...baseConfig,\n clientId: config.clientId!,\n loginUrl: config.loginUrl,\n };\n\n // Only add redirectUrl if provided\n if (config.redirectUrl) {\n authConfig.redirectUrl = config.redirectUrl;\n }\n\n // Only add logoutRedirectUrl if provided\n if (config.logoutRedirectUrl) {\n authConfig.logoutRedirectUrl = config.logoutRedirectUrl;\n }\n\n // Only add loginSuccessUrl if provided\n if (config.loginSuccessUrl) {\n authConfig.loginSuccessUrl = config.loginSuccessUrl;\n }\n\n this.auth = await CivicAuth.create(authConfig);\n // Check initial auth state\n const isAuthenticated = await this.auth.isAuthenticated();\n\n if (isAuthenticated) {\n await this.updateUserAndSession();\n this.setState({ authStatus: \"authenticated\" });\n } else {\n this.setState({ authStatus: \"unauthenticated\" });\n\n // Note: Preloading is now handled automatically by CivicAuth based on config.preloadIframe\n }\n\n this.setState({\n isLoading: false,\n displayMode: config.displayMode,\n });\n } catch (error) {\n // Reset promise on error so it can be retried\n this.initializationPromise = null;\n\n const authError =\n error instanceof Error\n ? error\n : new Error(\"Auth initialization failed\");\n this.setState({\n error: authError,\n authStatus: \"error\",\n isLoading: false,\n });\n throw authError;\n }\n }\n\n /**\n * Subscribe to state changes\n */\n subscribe(listener: StateListener): () => void {\n this.listeners.add(listener);\n return () => this.listeners.delete(listener);\n }\n\n /**\n * Get current state\n */\n getState(): GlobalAuthState {\n return { ...this.state };\n }\n\n /**\n * Get current configuration\n * Returns the current config or null if not initialized\n */\n getConfig(): GlobalAuthConfig | null {\n return this.config ? { ...this.config } : null;\n }\n\n /**\n * Sign in\n */\n async signIn(): Promise<{ user: User }> {\n if (!this.auth) {\n await this.initialize(this.config || {});\n }\n if (!this.auth) {\n throw new Error(\"Auth not initialized\");\n }\n\n const authResult = await this.auth.startAuthentication();\n\n // If authentication returned a user, use it directly\n if (authResult.user) {\n await this.updateUserAndSession();\n this.setState({\n user: authResult.user,\n authStatus: \"authenticated\",\n error: null,\n });\n return { user: authResult.user };\n }\n\n // Fallback: try to refresh user and session data\n await this.updateUserAndSession();\n\n // Check the current state for the user after refresh\n const currentState = this.getState();\n\n if (!currentState.user) {\n throw new Error(\"Authentication succeeded but no user was returned\");\n }\n\n // Return the user object from current state\n return { user: currentState.user };\n }\n\n /**\n * Sign out\n */\n async signOut(): Promise<void> {\n if (!this.auth) {\n await this.initialize(this.config || {});\n }\n if (!this.auth) {\n throw new Error(\"Auth not initialized\");\n }\n if (this.state.authStatus === \"unauthenticated\") {\n // Already signed out, no-op\n return;\n }\n await this.auth.logout();\n this.setState({\n user: null,\n session: null,\n authStatus: \"unauthenticated\",\n });\n }\n\n /**\n * Check if authentication is preloaded and ready for instant sign-in\n * @returns True if an iframe is preloaded and ready\n */\n isAuthenticationPreloaded(): boolean {\n return this.auth?.isAuthenticationPreloaded() ?? false;\n }\n\n /**\n * Enable or disable iframe preloading\n */\n setPreloadEnabled(enabled: boolean): void {\n if (!this.auth) {\n throw new Error(\"Auth not initialized\");\n }\n this.auth.setPreloadEnabled(enabled);\n }\n\n /**\n * Check if iframe preloading is enabled\n */\n getPreloadEnabled(): boolean {\n return this.auth?.getPreloadEnabled() ?? true;\n }\n\n /**\n * Reloads embedded authentication interface\n *\n * This method is specifically designed for embedded mode scenarios where the iframe\n * needs to be recreated after navigation or DOM changes. It delegates to the\n * underlying CivicAuth instance's reloadEmbedded method.\n *\n * @returns Promise that resolves when the embedded iframe is created\n * @throws {Error} If not in embedded mode or if auth is not initialized\n */\n async reloadEmbedded(): Promise<void> {\n if (!this.auth) {\n throw new Error(\"Auth not initialized. Call initialize() first.\");\n }\n\n return this.auth.reloadEmbedded();\n }\n\n /**\n * Reset authentication state when detected from back-forward cache (bfcache)\n * This fixes issues where sign-in button becomes unclickable after back navigation\n */\n resetOnBfcache(): void {\n if (!this.auth) return;\n\n // Reset internal CivicAuth state first\n this.auth.resetOnBfcache();\n\n // Reset auth state to unauthenticated to allow new sign-in attempts\n this.setState({\n authStatus: \"unauthenticated\",\n isLoading: false,\n error: null,\n user: null,\n session: null,\n });\n\n // Ensure iframe preloading state is refreshed if needed\n if (this.getPreloadEnabled()) {\n this.auth.setPreloadEnabled(true);\n }\n }\n\n /**\n * Check if config is the same (for idempotent initialization)\n */\n private isSameConfig(newConfig: GlobalAuthConfig): boolean {\n if (!this.config) return false;\n return (\n this.config.clientId === newConfig.clientId &&\n this.config.config?.oauthServer === newConfig.config?.oauthServer &&\n this.config.displayMode === newConfig.displayMode &&\n this.config.nonce === newConfig.nonce &&\n this.config.preloadIframe === newConfig.preloadIframe &&\n this.config.autoRedirect === newConfig.autoRedirect &&\n this.config?.onSignIn === newConfig?.onSignIn &&\n this.config?.onSignOut === newConfig?.onSignOut &&\n this.config?.onUrlChange === newConfig?.onUrlChange\n );\n }\n\n /**\n * Setup event listeners for auth state changes\n */\n private setupEventListeners(): void {\n if (!this.events) return;\n\n this.events.on(AuthEvent.SIGN_IN_STARTED, () => {\n this.setState({\n isLoading: true,\n authStatus: \"authenticating\",\n error: null,\n });\n });\n\n this.events.on(AuthEvent.TOKEN_REFRESH_COMPLETE, () => {\n this.setState({\n isLoading: false,\n authStatus: \"authenticated\",\n });\n this.updateUserAndSession();\n this.callbacks.onRefresh?.();\n });\n\n this.events.on(AuthEvent.SIGN_IN_COMPLETE, async () => {\n this.setState({\n isLoading: false,\n authStatus: \"authenticated\",\n error: null,\n });\n this.updateUserAndSession();\n await this.callbacks.onPreSignIn?.({\n user: this.state.user,\n session: this.state.session,\n });\n await this.callbacks.onSignIn?.({\n user: this.state.user,\n session: this.state.session,\n });\n });\n\n this.events.on(\n AuthEvent.SIGN_IN_ERROR,\n async (event?: SignInErrorEvent) => {\n const errorDetail = event?.detail || \"Authentication failed\";\n const authError = new Error(errorDetail);\n this.setState({\n isLoading: false,\n authStatus: \"error\",\n error: authError,\n });\n await this.callbacks.onPreSignIn?.({\n error: authError,\n });\n await this.callbacks.onSignIn?.({ error: authError });\n },\n );\n\n this.events.on(AuthEvent.SIGN_OUT_STARTED, () => {\n this.setState({\n isLoading: true,\n authStatus: \"signing_out\",\n error: null,\n });\n });\n\n this.events.on(AuthEvent.SIGN_OUT_COMPLETE, async () => {\n this.setState({\n isLoading: false,\n authStatus: \"unauthenticated\",\n user: null,\n session: null,\n error: null,\n });\n await this.callbacks.onPreSignOut?.({});\n await this.callbacks.onSignOut?.({});\n // if we have a logoutRedirectUrl in config, and it's different from current URL, load it\n if (this.config?.logoutRedirectUrl) {\n const currentPathAndQuery =\n window.location.pathname + window.location.search;\n\n // Parse the logout redirect URL to get its path and query\n const logoutUrl = new URL(\n this.config.logoutRedirectUrl,\n window.location.origin,\n );\n const logoutPathAndQuery = logoutUrl.pathname + logoutUrl.search;\n\n // Only redirect if current path + query is different from logout redirect URL\n if (currentPathAndQuery !== logoutPathAndQuery) {\n window.location.href = this.config.logoutRedirectUrl;\n }\n }\n });\n\n this.events.on(AuthEvent.SIGN_OUT_ERROR, async (error?: Error) => {\n const signOutError =\n error instanceof Error ? error : new Error(\"Sign-out failed\");\n this.setState({\n isLoading: false,\n authStatus: \"error\",\n error: signOutError,\n });\n await this.callbacks.onPreSignOut?.({ error: signOutError });\n await this.callbacks.onSignOut?.({ error: signOutError });\n });\n\n this.events.on(AuthEvent.USER_SESSION_CHANGED, () => {\n this.updateUserAndSession();\n });\n\n this.events.on(\n AuthEvent.URL_CHANGE,\n (event?: { detail?: string; url?: string; source?: string }) => {\n this.setState({\n authStatus: \"authenticating\", // Keep as authenticating since we're redirecting\n error: null,\n });\n // Call custom URL change handler if provided\n if (event?.url && this.callbacks.onUrlChange) {\n this.callbacks.onUrlChange(event.url, event.source);\n }\n },\n );\n }\n\n /**\n * Refresh user and session data\n */\n private async updateUserAndSession(): Promise<void> {\n if (!this.auth) return;\n\n try {\n const [session, user] = await Promise.all([\n this.auth.getCurrentSession(),\n this.auth.getCurrentUser(),\n ]);\n\n this.setState({ session, user });\n } catch (error) {\n const sessionError =\n error instanceof Error ? error : new Error(\"Failed to get session\");\n this.setState({ error: sessionError });\n }\n }\n\n /**\n * Update state and notify listeners\n */\n private setState(updates: Partial<GlobalAuthState>): void {\n this.state = { ...this.state, ...updates };\n this.listeners.forEach((listener) => listener(this.state));\n }\n\n /**\n * Cleanup auth instance\n */\n public async cleanup(): Promise<void> {\n if (this.auth) {\n await this.auth.destroy();\n this.auth = null;\n }\n this.events = null;\n this.config = null;\n this.initializationPromise = null; // Reset promise for clean re-initialization\n }\n}\n\nexport { GlobalAuthManager };\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { CivicAuth, type Session, type User } from "../../vanillajs/index.js";
|
|
4
|
+
import type { DisplayMode, ForwardedTokens } from "../../types.js";
|
|
5
|
+
export type AuthStatusEnum = "authenticated" | "unauthenticated" | "authenticating" | "error" | "signing_out";
|
|
6
|
+
export interface CivicAuthContextType {
|
|
7
|
+
auth: CivicAuth | null;
|
|
8
|
+
user: User | null;
|
|
9
|
+
session: Session | null;
|
|
10
|
+
isLoading: boolean;
|
|
11
|
+
authStatus: AuthStatusEnum;
|
|
12
|
+
error: Error | null;
|
|
13
|
+
idToken?: string;
|
|
14
|
+
accessToken?: string;
|
|
15
|
+
refreshToken?: string;
|
|
16
|
+
forwardedTokens?: ForwardedTokens;
|
|
17
|
+
signIn: () => Promise<{
|
|
18
|
+
user: User;
|
|
19
|
+
}>;
|
|
20
|
+
signOut: () => Promise<void>;
|
|
21
|
+
isAuthenticationPreloaded: () => boolean;
|
|
22
|
+
setPreloadEnabled: (enabled: boolean) => void;
|
|
23
|
+
getPreloadEnabled: () => boolean;
|
|
24
|
+
displayMode?: DisplayMode;
|
|
25
|
+
}
|
|
26
|
+
declare const CivicAuthContext: React.Context<CivicAuthContextType | null>;
|
|
27
|
+
export interface CivicAuthContextProviderProps {
|
|
28
|
+
children: ReactNode;
|
|
29
|
+
clientId: string;
|
|
30
|
+
redirectUrl?: string;
|
|
31
|
+
oauthServerBaseUrl?: string;
|
|
32
|
+
scopes?: string[];
|
|
33
|
+
displayMode?: DisplayMode;
|
|
34
|
+
iframeDisplayMode?: "modal" | "embedded";
|
|
35
|
+
onSignIn?: (error?: Error) => void;
|
|
36
|
+
onSignOut?: () => void;
|
|
37
|
+
nonce?: string;
|
|
38
|
+
authProcessTimeout?: number;
|
|
39
|
+
preloadIframe?: boolean;
|
|
40
|
+
}
|
|
41
|
+
export declare const CivicAuthContextProvider: React.FC<CivicAuthContextProviderProps>;
|
|
42
|
+
export declare const useCivicAuthContext: () => CivicAuthContextType;
|
|
43
|
+
export { CivicAuthContext };
|
|
44
|
+
//# sourceMappingURL=CivicAuthContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CivicAuthContext.d.ts","sourceRoot":"","sources":["../../../src/reactjs/providers/CivicAuthContext.tsx"],"names":[],"mappings":"AACA,OAAO,KAQN,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EACL,SAAS,EAET,KAAK,OAAO,EACZ,KAAK,IAAI,EACV,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AASnE,MAAM,MAAM,cAAc,GACtB,eAAe,GACf,iBAAiB,GACjB,gBAAgB,GAChB,OAAO,GACP,aAAa,CAAC;AAElB,MAAM,WAAW,oBAAoB;IAEnC,IAAI,EAAE,SAAS,GAAG,IAAI,CAAC;IAGvB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAGxB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,cAAc,CAAC;IAC3B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAGpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC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, useMemo, useRef, } from "react";
|
|
4
|
+
import { CivicAuth, AuthEvent, } from "../../vanillajs/index.js";
|
|
5
|
+
import { AuthenticationEvents } from "../../vanillajs/auth/AuthenticationEvents.js";
|
|
6
|
+
import { extractTokensFromSession } from "../../vanillajs/utils/auth-utils.js";
|
|
7
|
+
import { DEFAULT_AUTH_PROCESS_TIMEOUT } from "../../vanillajs/auth/types/AuthTypes.js";
|
|
8
|
+
const CivicAuthContext = createContext(null);
|
|
9
|
+
export const CivicAuthContextProvider = ({ children, clientId, redirectUrl, oauthServerBaseUrl = "https://auth.civic.com/oauth/", scopes = ["openid", "profile", "email", "offline_access"], displayMode = "iframe", iframeDisplayMode = "modal", onSignIn, onSignOut, nonce, authProcessTimeout = DEFAULT_AUTH_PROCESS_TIMEOUT, preloadIframe, }) => {
|
|
10
|
+
const [auth, setAuth] = useState(null);
|
|
11
|
+
const [user, setUser] = useState(null);
|
|
12
|
+
const [session, setSession] = useState(null);
|
|
13
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
14
|
+
const [authStatus, setAuthStatus] = useState("unauthenticated");
|
|
15
|
+
const [error, setError] = useState(null);
|
|
16
|
+
// Track initialization to prevent double-execution in React StrictMode
|
|
17
|
+
const initializationRef = useRef({
|
|
18
|
+
isInitializing: false,
|
|
19
|
+
isInitialized: false,
|
|
20
|
+
});
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
let isMounted = true;
|
|
23
|
+
// Prevent double initialization in React StrictMode
|
|
24
|
+
if (initializationRef.current.isInitializing ||
|
|
25
|
+
initializationRef.current.isInitialized) {
|
|
26
|
+
// `[CivicAuthContext] Skipping initialization ${initId} - already initializing/initialized`,
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// Capture ref value at effect setup time for cleanup
|
|
30
|
+
const initializationState = initializationRef.current;
|
|
31
|
+
initializationRef.current.isInitializing = true;
|
|
32
|
+
const refreshUserAndSession = async () => {
|
|
33
|
+
if (!auth)
|
|
34
|
+
return;
|
|
35
|
+
try {
|
|
36
|
+
const currentSession = await auth.getCurrentSession();
|
|
37
|
+
const currentUser = await auth.getCurrentUser();
|
|
38
|
+
if (isMounted) {
|
|
39
|
+
setSession(currentSession);
|
|
40
|
+
setUser(currentUser);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
if (isMounted) {
|
|
45
|
+
const sessionError = err instanceof Error ? err : new Error("Failed to get session");
|
|
46
|
+
setError(sessionError);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const initializeAuth = async () => {
|
|
51
|
+
try {
|
|
52
|
+
const events = new AuthenticationEvents();
|
|
53
|
+
// Set up event listeners
|
|
54
|
+
events.on(AuthEvent.SIGN_IN_STARTED, () => {
|
|
55
|
+
if (isMounted) {
|
|
56
|
+
setIsLoading(true);
|
|
57
|
+
setAuthStatus("authenticating");
|
|
58
|
+
setError(null);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
events.on(AuthEvent.SIGN_IN_COMPLETE, () => {
|
|
62
|
+
if (isMounted) {
|
|
63
|
+
setIsLoading(false);
|
|
64
|
+
setAuthStatus("authenticated");
|
|
65
|
+
setError(null);
|
|
66
|
+
onSignIn?.();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
events.on(AuthEvent.SIGN_IN_ERROR, (event) => {
|
|
70
|
+
if (isMounted) {
|
|
71
|
+
setIsLoading(false);
|
|
72
|
+
setAuthStatus("error");
|
|
73
|
+
const errorDetail = event?.detail || "Authentication failed";
|
|
74
|
+
const authError = new Error(errorDetail);
|
|
75
|
+
setError(authError);
|
|
76
|
+
onSignIn?.(authError);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
events.on(AuthEvent.SIGN_OUT_STARTED, () => {
|
|
80
|
+
if (isMounted) {
|
|
81
|
+
setIsLoading(true);
|
|
82
|
+
setAuthStatus("signing_out");
|
|
83
|
+
setError(null);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
events.on(AuthEvent.SIGN_OUT_COMPLETE, () => {
|
|
87
|
+
if (isMounted) {
|
|
88
|
+
setIsLoading(false);
|
|
89
|
+
setAuthStatus("unauthenticated");
|
|
90
|
+
setUser(null);
|
|
91
|
+
setSession(null);
|
|
92
|
+
setError(null);
|
|
93
|
+
onSignOut?.();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
events.on(AuthEvent.USER_SESSION_CHANGED, () => {
|
|
97
|
+
if (isMounted) {
|
|
98
|
+
refreshUserAndSession();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
const authInstance = await CivicAuth.create({
|
|
102
|
+
clientId,
|
|
103
|
+
redirectUrl: redirectUrl ||
|
|
104
|
+
`${window.location.origin}${window.location.pathname}`,
|
|
105
|
+
oauthServerBaseUrl,
|
|
106
|
+
scopes,
|
|
107
|
+
displayMode,
|
|
108
|
+
iframeDisplayMode,
|
|
109
|
+
nonce,
|
|
110
|
+
authProcessTimeout,
|
|
111
|
+
preloadIframe,
|
|
112
|
+
events,
|
|
113
|
+
});
|
|
114
|
+
if (isMounted) {
|
|
115
|
+
setAuth(authInstance);
|
|
116
|
+
// Mark initialization as complete
|
|
117
|
+
initializationRef.current.isInitializing = false;
|
|
118
|
+
initializationRef.current.isInitialized = true;
|
|
119
|
+
// Check initial auth state
|
|
120
|
+
const isAuthenticated = await authInstance.isAuthenticated();
|
|
121
|
+
if (isAuthenticated) {
|
|
122
|
+
setAuthStatus("authenticated");
|
|
123
|
+
await refreshUserAndSession();
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
setAuthStatus("unauthenticated");
|
|
127
|
+
// Note: Preloading is now handled automatically by CivicAuth based on config.preloadIframe
|
|
128
|
+
}
|
|
129
|
+
// Mark initialization as complete
|
|
130
|
+
setIsLoading(false);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
console.error(err);
|
|
135
|
+
if (isMounted) {
|
|
136
|
+
const initError = err instanceof Error ? err : new Error("Failed to initialize auth");
|
|
137
|
+
setError(initError);
|
|
138
|
+
setAuthStatus("error");
|
|
139
|
+
setIsLoading(false); // Stop loading even on error
|
|
140
|
+
// Mark initialization as failed
|
|
141
|
+
initializationRef.current.isInitializing = false;
|
|
142
|
+
// Don't mark as initialized on error so it can be retried
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
initializeAuth();
|
|
147
|
+
return () => {
|
|
148
|
+
isMounted = false;
|
|
149
|
+
// Reset initialization guards to allow remount to reinitialize
|
|
150
|
+
// This is necessary for React StrictMode compatibility
|
|
151
|
+
if (initializationState.isInitializing) {
|
|
152
|
+
initializationState.isInitializing = false;
|
|
153
|
+
initializationState.isInitialized = false;
|
|
154
|
+
}
|
|
155
|
+
if (auth) {
|
|
156
|
+
auth.destroy();
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
// Refresh user and session when auth instance changes
|
|
160
|
+
/*
|
|
161
|
+
* Intentionally omitting dependencies to prevent infinite loops.
|
|
162
|
+
* Adding auth, onSignIn, onSignOut, and scopes to the dependency array would cause
|
|
163
|
+
* the effect to re-run whenever these values change, which could lead to unnecessary
|
|
164
|
+
* re-renders and potential infinite loops since the effect updates state that might
|
|
165
|
+
* trigger re-renders of parent components.
|
|
166
|
+
*
|
|
167
|
+
* IMPORTANT: redirectUrl is intentionally omitted to prevent re-initialization
|
|
168
|
+
* during OAuth callback when URL parameters change, which would cause
|
|
169
|
+
* "invalid_grant" errors due to authorization code reuse.
|
|
170
|
+
*/
|
|
171
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
172
|
+
}, [
|
|
173
|
+
clientId,
|
|
174
|
+
oauthServerBaseUrl,
|
|
175
|
+
displayMode,
|
|
176
|
+
iframeDisplayMode,
|
|
177
|
+
nonce,
|
|
178
|
+
authProcessTimeout,
|
|
179
|
+
preloadIframe,
|
|
180
|
+
]);
|
|
181
|
+
// This is on load to get the user and session
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
if (auth && authStatus === "authenticated") {
|
|
184
|
+
const refreshUserAndSession = async () => {
|
|
185
|
+
try {
|
|
186
|
+
const currentSession = await auth.getCurrentSession();
|
|
187
|
+
const currentUser = await auth.getCurrentUser();
|
|
188
|
+
setSession(currentSession);
|
|
189
|
+
setUser(currentUser);
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
const sessionError = err instanceof Error ? err : new Error("Failed to get session");
|
|
193
|
+
setError(sessionError);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
refreshUserAndSession();
|
|
197
|
+
}
|
|
198
|
+
}, [auth, authStatus]);
|
|
199
|
+
const signIn = useCallback(async () => {
|
|
200
|
+
if (!auth) {
|
|
201
|
+
// If auth is still loading, provide a more helpful error
|
|
202
|
+
if (isLoading) {
|
|
203
|
+
throw new Error("Authentication is still initializing, please wait...");
|
|
204
|
+
}
|
|
205
|
+
throw new Error("Auth not initialized");
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
const { user } = await auth.startAuthentication();
|
|
209
|
+
// Refresh user and session after successful authentication
|
|
210
|
+
const currentSession = await auth.getCurrentSession();
|
|
211
|
+
setSession(currentSession);
|
|
212
|
+
setUser(user ?? null);
|
|
213
|
+
// Ensure we have a user to return
|
|
214
|
+
if (!user) {
|
|
215
|
+
throw new Error("Authentication succeeded but no user was returned");
|
|
216
|
+
}
|
|
217
|
+
// Return the user object
|
|
218
|
+
return { user };
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
const signInError = err instanceof Error ? err : new Error("Sign in failed");
|
|
222
|
+
setError(signInError);
|
|
223
|
+
throw signInError;
|
|
224
|
+
}
|
|
225
|
+
}, [auth, isLoading]);
|
|
226
|
+
const signOut = useCallback(async () => {
|
|
227
|
+
if (!auth) {
|
|
228
|
+
// If auth is still loading, provide a more helpful error
|
|
229
|
+
if (isLoading) {
|
|
230
|
+
throw new Error("Authentication is still initializing, please wait...");
|
|
231
|
+
}
|
|
232
|
+
throw new Error("Auth not initialized");
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
await auth.logout();
|
|
236
|
+
setUser(null);
|
|
237
|
+
setSession(null);
|
|
238
|
+
}
|
|
239
|
+
catch (err) {
|
|
240
|
+
const signOutError = err instanceof Error ? err : new Error("Sign out failed");
|
|
241
|
+
setError(signOutError);
|
|
242
|
+
throw signOutError;
|
|
243
|
+
}
|
|
244
|
+
}, [auth, isLoading]);
|
|
245
|
+
const isAuthenticationPreloaded = useCallback(() => {
|
|
246
|
+
return auth?.isAuthenticationPreloaded() ?? false;
|
|
247
|
+
}, [auth]);
|
|
248
|
+
const setPreloadEnabled = useCallback((enabled) => {
|
|
249
|
+
if (!auth) {
|
|
250
|
+
throw new Error("Auth not initialized");
|
|
251
|
+
}
|
|
252
|
+
auth.setPreloadEnabled(enabled);
|
|
253
|
+
}, [auth]);
|
|
254
|
+
const getPreloadEnabled = useCallback(() => {
|
|
255
|
+
return auth?.getPreloadEnabled() ?? true;
|
|
256
|
+
}, [auth]);
|
|
257
|
+
// Extract tokens from session
|
|
258
|
+
const idToken = session?.idToken;
|
|
259
|
+
const accessToken = session?.accessToken;
|
|
260
|
+
const refreshToken = session?.refreshToken;
|
|
261
|
+
// Extract forwardedTokens from session's ID token
|
|
262
|
+
const forwardedTokens = useMemo(() => {
|
|
263
|
+
if (!session)
|
|
264
|
+
return undefined;
|
|
265
|
+
const tokens = extractTokensFromSession(session);
|
|
266
|
+
return tokens.forwardedTokens;
|
|
267
|
+
}, [session]);
|
|
268
|
+
const contextValue = useMemo(() => ({
|
|
269
|
+
auth,
|
|
270
|
+
user,
|
|
271
|
+
session,
|
|
272
|
+
isLoading,
|
|
273
|
+
authStatus,
|
|
274
|
+
error,
|
|
275
|
+
idToken,
|
|
276
|
+
accessToken,
|
|
277
|
+
refreshToken,
|
|
278
|
+
forwardedTokens,
|
|
279
|
+
signIn,
|
|
280
|
+
signOut,
|
|
281
|
+
isAuthenticationPreloaded,
|
|
282
|
+
setPreloadEnabled,
|
|
283
|
+
getPreloadEnabled,
|
|
284
|
+
displayMode,
|
|
285
|
+
}), [
|
|
286
|
+
auth,
|
|
287
|
+
user,
|
|
288
|
+
session,
|
|
289
|
+
isLoading,
|
|
290
|
+
authStatus,
|
|
291
|
+
error,
|
|
292
|
+
idToken,
|
|
293
|
+
accessToken,
|
|
294
|
+
refreshToken,
|
|
295
|
+
forwardedTokens,
|
|
296
|
+
signIn,
|
|
297
|
+
signOut,
|
|
298
|
+
isAuthenticationPreloaded,
|
|
299
|
+
setPreloadEnabled,
|
|
300
|
+
getPreloadEnabled,
|
|
301
|
+
displayMode,
|
|
302
|
+
]);
|
|
303
|
+
return (_jsx(CivicAuthContext.Provider, { value: contextValue, children: children }));
|
|
304
|
+
};
|
|
305
|
+
export const useCivicAuthContext = () => {
|
|
306
|
+
const context = useContext(CivicAuthContext);
|
|
307
|
+
if (!context) {
|
|
308
|
+
throw new Error("useCivicAuthContext must be used within a CivicAuthContextProvider");
|
|
309
|
+
}
|
|
310
|
+
return context;
|
|
311
|
+
};
|
|
312
|
+
export { CivicAuthContext };
|
|
313
|
+
//# sourceMappingURL=CivicAuthContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CivicAuthContext.js","sourceRoot":"","sources":["../../../src/reactjs/providers/CivicAuthContext.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,KAAK,EAAE,EACZ,aAAa,EACb,UAAU,EACV,SAAS,EACT,QAAQ,EACR,WAAW,EACX,OAAO,EACP,MAAM,GACP,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,SAAS,EACT,SAAS,GAGV,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AAEpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,C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AAO,CAAC;AACjB,CAAC,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["\"use client\";\nimport React, {\n createContext,\n useContext,\n useEffect,\n useState,\n useCallback,\n useMemo,\n useRef,\n} from \"react\";\nimport type { ReactNode } from \"react\";\nimport {\n CivicAuth,\n AuthEvent,\n type Session,\n type User,\n} from \"../../vanillajs/index.js\";\nimport { AuthenticationEvents } from \"../../vanillajs/auth/AuthenticationEvents.js\";\nimport type { DisplayMode, ForwardedTokens } from \"../../types.js\";\nimport { extractTokensFromSession } from \"../../vanillajs/utils/auth-utils.js\";\nimport { DEFAULT_AUTH_PROCESS_TIMEOUT } from \"../../vanillajs/auth/types/AuthTypes.js\";\n\n// Event payload interfaces\ninterface SignInErrorEvent {\n detail: string;\n}\n\nexport type AuthStatusEnum =\n | \"authenticated\"\n | \"unauthenticated\"\n | \"authenticating\"\n | \"error\"\n | \"signing_out\";\n\nexport interface CivicAuthContextType {\n // Core auth instance\n auth: CivicAuth | null;\n\n // User and session state\n user: User | null;\n session: Session | null;\n\n // Auth state\n isLoading: boolean;\n authStatus: AuthStatusEnum;\n error: Error | null;\n\n // Tokens\n idToken?: string;\n accessToken?: string;\n refreshToken?: string;\n forwardedTokens?: ForwardedTokens;\n\n // Auth methods\n signIn: () => Promise<{ user: User }>;\n signOut: () => Promise<void>;\n\n // Preloading methods\n isAuthenticationPreloaded: () => boolean;\n setPreloadEnabled: (enabled: boolean) => void;\n getPreloadEnabled: () => boolean;\n\n // Config\n displayMode?: DisplayMode;\n}\n\nconst CivicAuthContext = createContext<CivicAuthContextType | null>(null);\n\nexport interface CivicAuthContextProviderProps {\n children: ReactNode;\n clientId: string;\n redirectUrl?: string;\n oauthServerBaseUrl?: string;\n scopes?: string[];\n displayMode?: DisplayMode;\n iframeDisplayMode?: \"modal\" | \"embedded\";\n onSignIn?: (error?: Error) => void;\n onSignOut?: () => void;\n nonce?: string;\n authProcessTimeout?: number;\n preloadIframe?: boolean;\n}\n\nexport const CivicAuthContextProvider: React.FC<\n CivicAuthContextProviderProps\n> = ({\n children,\n clientId,\n redirectUrl,\n oauthServerBaseUrl = \"https://auth.civic.com/oauth/\",\n scopes = [\"openid\", \"profile\", \"email\", \"offline_access\"],\n displayMode = \"iframe\",\n iframeDisplayMode = \"modal\",\n onSignIn,\n onSignOut,\n nonce,\n authProcessTimeout = DEFAULT_AUTH_PROCESS_TIMEOUT,\n preloadIframe,\n}) => {\n const [auth, setAuth] = useState<CivicAuth | null>(null);\n const [user, setUser] = useState<User | null>(null);\n const [session, setSession] = useState<Session | null>(null);\n const [isLoading, setIsLoading] = useState(true);\n const [authStatus, setAuthStatus] =\n useState<AuthStatusEnum>(\"unauthenticated\");\n const [error, setError] = useState<Error | null>(null);\n\n // Track initialization to prevent double-execution in React StrictMode\n const initializationRef = useRef<{\n isInitializing: boolean;\n isInitialized: boolean;\n }>({\n isInitializing: false,\n isInitialized: false,\n });\n\n useEffect(() => {\n let isMounted = true;\n\n // Prevent double initialization in React StrictMode\n if (\n initializationRef.current.isInitializing ||\n initializationRef.current.isInitialized\n ) {\n // `[CivicAuthContext] Skipping initialization ${initId} - already initializing/initialized`,\n\n return;\n }\n\n // Capture ref value at effect setup time for cleanup\n const initializationState = initializationRef.current;\n\n initializationRef.current.isInitializing = true;\n\n const refreshUserAndSession = async () => {\n if (!auth) return;\n\n try {\n const currentSession = await auth.getCurrentSession();\n const currentUser = await auth.getCurrentUser();\n\n if (isMounted) {\n setSession(currentSession);\n setUser(currentUser);\n }\n } catch (err) {\n if (isMounted) {\n const sessionError =\n err instanceof Error ? err : new Error(\"Failed to get session\");\n setError(sessionError);\n }\n }\n };\n\n const initializeAuth = async () => {\n try {\n const events = new AuthenticationEvents();\n\n // Set up event listeners\n events.on(AuthEvent.SIGN_IN_STARTED, () => {\n if (isMounted) {\n setIsLoading(true);\n setAuthStatus(\"authenticating\");\n setError(null);\n }\n });\n\n events.on(AuthEvent.SIGN_IN_COMPLETE, () => {\n if (isMounted) {\n setIsLoading(false);\n setAuthStatus(\"authenticated\");\n setError(null);\n onSignIn?.();\n }\n });\n\n events.on(AuthEvent.SIGN_IN_ERROR, (event?: SignInErrorEvent) => {\n if (isMounted) {\n setIsLoading(false);\n setAuthStatus(\"error\");\n const errorDetail = event?.detail || \"Authentication failed\";\n const authError = new Error(errorDetail);\n setError(authError);\n onSignIn?.(authError);\n }\n });\n\n events.on(AuthEvent.SIGN_OUT_STARTED, () => {\n if (isMounted) {\n setIsLoading(true);\n setAuthStatus(\"signing_out\");\n setError(null);\n }\n });\n\n events.on(AuthEvent.SIGN_OUT_COMPLETE, () => {\n if (isMounted) {\n setIsLoading(false);\n setAuthStatus(\"unauthenticated\");\n setUser(null);\n setSession(null);\n setError(null);\n onSignOut?.();\n }\n });\n\n events.on(AuthEvent.USER_SESSION_CHANGED, () => {\n if (isMounted) {\n refreshUserAndSession();\n }\n });\n\n const authInstance = await CivicAuth.create({\n clientId,\n redirectUrl:\n redirectUrl ||\n `${window.location.origin}${window.location.pathname}`,\n oauthServerBaseUrl,\n scopes,\n displayMode,\n iframeDisplayMode,\n nonce,\n authProcessTimeout,\n preloadIframe,\n events,\n });\n\n if (isMounted) {\n setAuth(authInstance);\n\n // Mark initialization as complete\n initializationRef.current.isInitializing = false;\n initializationRef.current.isInitialized = true;\n\n // Check initial auth state\n const isAuthenticated = await authInstance.isAuthenticated();\n if (isAuthenticated) {\n setAuthStatus(\"authenticated\");\n await refreshUserAndSession();\n } else {\n setAuthStatus(\"unauthenticated\");\n\n // Note: Preloading is now handled automatically by CivicAuth based on config.preloadIframe\n }\n\n // Mark initialization as complete\n setIsLoading(false);\n }\n } catch (err) {\n console.error(err);\n if (isMounted) {\n const initError =\n err instanceof Error ? err : new Error(\"Failed to initialize auth\");\n setError(initError);\n setAuthStatus(\"error\");\n setIsLoading(false); // Stop loading even on error\n\n // Mark initialization as failed\n initializationRef.current.isInitializing = false;\n // Don't mark as initialized on error so it can be retried\n }\n }\n };\n\n initializeAuth();\n\n return () => {\n isMounted = false;\n\n // Reset initialization guards to allow remount to reinitialize\n // This is necessary for React StrictMode compatibility\n if (initializationState.isInitializing) {\n initializationState.isInitializing = false;\n initializationState.isInitialized = false;\n }\n\n if (auth) {\n auth.destroy();\n }\n };\n // Refresh user and session when auth instance changes\n /*\n * Intentionally omitting dependencies to prevent infinite loops.\n * Adding auth, onSignIn, onSignOut, and scopes to the dependency array would cause\n * the effect to re-run whenever these values change, which could lead to unnecessary\n * re-renders and potential infinite loops since the effect updates state that might\n * trigger re-renders of parent components.\n *\n * IMPORTANT: redirectUrl is intentionally omitted to prevent re-initialization\n * during OAuth callback when URL parameters change, which would cause\n * \"invalid_grant\" errors due to authorization code reuse.\n */\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n clientId,\n oauthServerBaseUrl,\n displayMode,\n iframeDisplayMode,\n nonce,\n authProcessTimeout,\n preloadIframe,\n ]);\n\n // This is on load to get the user and session\n useEffect(() => {\n if (auth && authStatus === \"authenticated\") {\n const refreshUserAndSession = async () => {\n try {\n const currentSession = await auth.getCurrentSession();\n const currentUser = await auth.getCurrentUser();\n setSession(currentSession);\n setUser(currentUser);\n } catch (err) {\n const sessionError =\n err instanceof Error ? err : new Error(\"Failed to get session\");\n setError(sessionError);\n }\n };\n\n refreshUserAndSession();\n }\n }, [auth, authStatus]);\n\n const signIn = useCallback(async () => {\n if (!auth) {\n // If auth is still loading, provide a more helpful error\n if (isLoading) {\n throw new Error(\"Authentication is still initializing, please wait...\");\n }\n throw new Error(\"Auth not initialized\");\n }\n\n try {\n const { user } = await auth.startAuthentication();\n\n // Refresh user and session after successful authentication\n const currentSession = await auth.getCurrentSession();\n\n setSession(currentSession);\n setUser(user ?? null);\n\n // Ensure we have a user to return\n if (!user) {\n throw new Error(\"Authentication succeeded but no user was returned\");\n }\n\n // Return the user object\n return { user };\n } catch (err) {\n const signInError =\n err instanceof Error ? err : new Error(\"Sign in failed\");\n setError(signInError);\n throw signInError;\n }\n }, [auth, isLoading]);\n\n const signOut = useCallback(async () => {\n if (!auth) {\n // If auth is still loading, provide a more helpful error\n if (isLoading) {\n throw new Error(\"Authentication is still initializing, please wait...\");\n }\n throw new Error(\"Auth not initialized\");\n }\n\n try {\n await auth.logout();\n setUser(null);\n setSession(null);\n } catch (err) {\n const signOutError =\n err instanceof Error ? err : new Error(\"Sign out failed\");\n setError(signOutError);\n throw signOutError;\n }\n }, [auth, isLoading]);\n\n const isAuthenticationPreloaded = useCallback(() => {\n return auth?.isAuthenticationPreloaded() ?? false;\n }, [auth]);\n\n const setPreloadEnabled = useCallback(\n (enabled: boolean) => {\n if (!auth) {\n throw new Error(\"Auth not initialized\");\n }\n auth.setPreloadEnabled(enabled);\n },\n [auth],\n );\n\n const getPreloadEnabled = useCallback(() => {\n return auth?.getPreloadEnabled() ?? true;\n }, [auth]);\n\n // Extract tokens from session\n const idToken = session?.idToken;\n const accessToken = session?.accessToken;\n const refreshToken = session?.refreshToken;\n\n // Extract forwardedTokens from session's ID token\n const forwardedTokens = useMemo(() => {\n if (!session) return undefined;\n const tokens = extractTokensFromSession(session);\n return tokens.forwardedTokens;\n }, [session]);\n\n const contextValue: CivicAuthContextType = useMemo(\n () => ({\n auth,\n user,\n session,\n isLoading,\n authStatus,\n error,\n idToken,\n accessToken,\n refreshToken,\n forwardedTokens,\n signIn,\n signOut,\n isAuthenticationPreloaded,\n setPreloadEnabled,\n getPreloadEnabled,\n displayMode,\n }),\n [\n auth,\n user,\n session,\n isLoading,\n authStatus,\n error,\n idToken,\n accessToken,\n refreshToken,\n forwardedTokens,\n signIn,\n signOut,\n isAuthenticationPreloaded,\n setPreloadEnabled,\n getPreloadEnabled,\n displayMode,\n ],\n );\n\n return (\n <CivicAuthContext.Provider value={contextValue}>\n {children}\n </CivicAuthContext.Provider>\n );\n};\n\nexport const useCivicAuthContext = (): CivicAuthContextType => {\n const context = useContext(CivicAuthContext);\n if (!context) {\n throw new Error(\n \"useCivicAuthContext must be used within a CivicAuthContextProvider\",\n );\n }\n return context;\n};\n\nexport { CivicAuthContext };\n"]}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export { UserProvider, UserContext, type UserContextType, } from "../../shared/providers/UserProvider.js";
|
|
2
|
-
export { TokenProvider, TokenContext, type TokenContextType, } from "../../shared/providers/TokenProvider.js";
|
|
3
|
-
export { SessionProvider, SessionContext, type SessionContextType, } from "../../shared/providers/SessionProvider.js";
|
|
4
1
|
export { AuthContext } from "../../shared/providers/AuthContext.js";
|
|
5
2
|
export type { AuthContextType } from "../../shared/providers/AuthContext.js";
|
|
6
3
|
export { CivicAuthProvider, type CivicAuthProviderProps, } from "../../reactjs/providers/CivicAuthProvider.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reactjs/providers/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reactjs/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChE,YAAY,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAGzE,OAAO,EACL,iBAAiB,EACjB,KAAK,sBAAsB,GAC5B,MAAM,0CAA0C,CAAC"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
// Legacy exports for backward compatibility
|
|
2
|
-
export { UserProvider, UserContext, } from "../../shared/providers/UserProvider.js";
|
|
3
|
-
export { TokenProvider, TokenContext, } from "../../shared/providers/TokenProvider.js";
|
|
4
|
-
export { SessionProvider, SessionContext, } from "../../shared/providers/SessionProvider.js";
|
|
5
1
|
export { AuthContext } from "../../shared/providers/AuthContext.js";
|
|
6
2
|
// Main exports - new VanillaJS-based implementation
|
|
7
3
|
export { CivicAuthProvider, } from "../../reactjs/providers/CivicAuthProvider.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reactjs/providers/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reactjs/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAGhE,oDAAoD;AACpD,OAAO,EACL,iBAAiB,GAElB,MAAM,0CAA0C,CAAC","sourcesContent":["export { AuthContext } from \"@/shared/providers/AuthContext.js\";\nexport type { AuthContextType } from \"@/shared/providers/AuthContext.js\";\n\n// Main exports - new VanillaJS-based implementation\nexport {\n CivicAuthProvider,\n type CivicAuthProviderProps,\n} from \"@/reactjs/providers/CivicAuthProvider.js\";\n"]}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
export { useToken } from "../../shared/hooks/useToken.js";
|
|
2
|
-
export { useSession } from "../../shared/hooks/useSession.js";
|
|
3
|
-
export { useCivicAuthConfig } from "../../shared/hooks/useCivicAuthConfig.js";
|
|
4
|
-
export { useOAuthEndpoints } from "../../shared/hooks/useOAuthEndpoints.js";
|
|
5
|
-
export { useCurrentUrl } from "../../shared/hooks/useCurrentUrl.js";
|
|
6
|
-
export { useClientTokenExchangeSession } from "../../shared/hooks/useClientTokenExchangeSession.js";
|
|
7
|
-
export { useWindowFocused } from "../../shared/hooks/useWindowFocused.js";
|
|
8
1
|
export { useBfcacheHandler } from "../../shared/hooks/useBfcacheHandler.js";
|
|
9
2
|
export { useAuthStatus } from "../../shared/providers/AuthStatusContext.js";
|
|
10
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC"}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
export { useToken } from "../../shared/hooks/useToken.js";
|
|
2
|
-
export { useSession } from "../../shared/hooks/useSession.js";
|
|
3
|
-
export { useCivicAuthConfig } from "../../shared/hooks/useCivicAuthConfig.js";
|
|
4
|
-
export { useOAuthEndpoints } from "../../shared/hooks/useOAuthEndpoints.js";
|
|
5
|
-
export { useCurrentUrl } from "../../shared/hooks/useCurrentUrl.js";
|
|
6
|
-
export { useClientTokenExchangeSession } from "../../shared/hooks/useClientTokenExchangeSession.js";
|
|
7
|
-
export { useWindowFocused } from "../../shared/hooks/useWindowFocused.js";
|
|
8
1
|
export { useBfcacheHandler } from "../../shared/hooks/useBfcacheHandler.js";
|
|
9
2
|
export { useAuthStatus } from "../../shared/providers/AuthStatusContext.js";
|
|
10
3
|
//# sourceMappingURL=index.js.map
|