@civic/auth 0.11.2-beta.0 → 0.11.3-alpha.0

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/nextjs/NextClientAuthenticationRefresher.d.ts +8 -0
  6. package/dist/nextjs/NextClientAuthenticationRefresher.d.ts.map +1 -0
  7. package/dist/nextjs/NextClientAuthenticationRefresher.js +24 -0
  8. package/dist/nextjs/NextClientAuthenticationRefresher.js.map +1 -0
  9. package/dist/nextjs/NextServerAuthenticationRefresherImpl.d.ts +12 -0
  10. package/dist/nextjs/NextServerAuthenticationRefresherImpl.d.ts.map +1 -0
  11. package/dist/nextjs/NextServerAuthenticationRefresherImpl.js +25 -0
  12. package/dist/nextjs/NextServerAuthenticationRefresherImpl.js.map +1 -0
  13. package/dist/nextjs/hooks/useRefresh.d.ts +5 -0
  14. package/dist/nextjs/hooks/useRefresh.d.ts.map +1 -0
  15. package/dist/nextjs/hooks/useRefresh.js +57 -0
  16. package/dist/nextjs/hooks/useRefresh.js.map +1 -0
  17. package/dist/nextjs/providers/NextAuthProvider.d.ts +1 -1
  18. package/dist/nextjs/providers/NextAuthProvider.d.ts.map +1 -1
  19. package/dist/nextjs/providers/NextAuthProvider.js.map +1 -1
  20. package/dist/nextjs/providers/NextAuthProviderClient.d.ts.map +1 -1
  21. package/dist/nextjs/providers/NextAuthProviderClient.js +2 -3
  22. package/dist/nextjs/providers/NextAuthProviderClient.js.map +1 -1
  23. package/dist/react-router-7/auth-loader.d.ts +18 -0
  24. package/dist/react-router-7/auth-loader.d.ts.map +1 -0
  25. package/dist/react-router-7/auth-loader.js +36 -0
  26. package/dist/react-router-7/auth-loader.js.map +1 -0
  27. package/dist/reactjs/core/GlobalAuthManager.d.ts.map +1 -1
  28. package/dist/reactjs/core/GlobalAuthManager.js +17 -0
  29. package/dist/reactjs/core/GlobalAuthManager.js.map +1 -1
  30. package/dist/reactjs/providers/CivicAuthContext.d.ts +44 -0
  31. package/dist/reactjs/providers/CivicAuthContext.d.ts.map +1 -0
  32. package/dist/reactjs/providers/CivicAuthContext.js +313 -0
  33. package/dist/reactjs/providers/CivicAuthContext.js.map +1 -0
  34. package/dist/reactjs/providers/index.d.ts +0 -3
  35. package/dist/reactjs/providers/index.d.ts.map +1 -1
  36. package/dist/reactjs/providers/index.js +0 -4
  37. package/dist/reactjs/providers/index.js.map +1 -1
  38. package/dist/shared/hooks/index.d.ts +0 -7
  39. package/dist/shared/hooks/index.d.ts.map +1 -1
  40. package/dist/shared/hooks/index.js +0 -7
  41. package/dist/shared/hooks/index.js.map +1 -1
  42. package/dist/shared/hooks/useRefresh.d.ts +6 -0
  43. package/dist/shared/hooks/useRefresh.d.ts.map +1 -0
  44. package/dist/shared/hooks/useRefresh.js +47 -0
  45. package/dist/shared/hooks/useRefresh.js.map +1 -0
  46. package/dist/shared/version.d.ts +1 -1
  47. package/dist/shared/version.d.ts.map +1 -1
  48. package/dist/shared/version.js +1 -1
  49. package/dist/shared/version.js.map +1 -1
  50. package/dist/tsconfig.tsbuildinfo +1 -0
  51. package/dist/types.d.ts +9 -0
  52. package/dist/types.d.ts.map +1 -1
  53. package/dist/types.js.map +1 -1
  54. package/dist/vanillajs/auth/CivicAuth.d.ts.map +1 -1
  55. package/dist/vanillajs/auth/CivicAuth.js +4 -0
  56. package/dist/vanillajs/auth/CivicAuth.js.map +1 -1
  57. package/package.json +3 -3
@@ -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,M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EAAE,MAAM,CAAC;IAC5B,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,eAAO,MAAM,wBAAwB,EAAE,KAAK,CAAC,EAAE,CAC7C,6BAA6B,CA+W9B,CAAC;AAEF,eAAO,MAAM,mBAAmB,QAAO,oBAQtC,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,313 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
3
+ import React, { createContext, useContext, useEffect, useState, useCallback, 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,CAAC;AA8CvF,MAAM,gBAAgB,GAAG,aAAa,CAA8B,IAAI,CAAC,CAAC;AAiB1E,MAAM,CAAC,MAAM,wBAAwB,GAEjC,CAAC,EACH,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,kBAAkB,GAAG,+BAA+B,EACpD,MAAM,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,CAAC,EACzD,WAAW,GAAG,QAAQ,EACtB,iBAAiB,GAAG,OAAO,EAC3B,QAAQ,EACR,SAAS,EACT,KAAK,EACL,kBAAkB,GAAG,4BAA4B,EACjD,aAAa,GACd,EAAE,EAAE;IACH,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAmB,IAAI,CAAC,CAAC;IACzD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAc,IAAI,CAAC,CAAC;IACpD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAiB,IAAI,CAAC,CAAC;IAC7D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QA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;QACE,IAAI;QACJ,IAAI;QACJ,OAAO;QACP,SAAS;QACT,UAAU;QACV,KAAK;QACL,OAAO;QACP,WAAW;QACX,YAAY;QACZ,eAAe;QACf,MAAM;QACN,OAAO;QACP,yBAAyB;QACzB,iBAAiB;QACjB,iBAAiB;QACjB,WAAW;KACZ,CACF,CAAC;IAEF,OAAO,CACL,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAC3C,QAAQ,GACiB,CAC7B,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAyB,EAAE;IAC5D,MAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC7C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,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":"AACA,OAAO,EACL,YAAY,EACZ,WAAW,EACX,KAAK,eAAe,GACrB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EACL,aAAa,EACb,YAAY,EACZ,KAAK,gBAAgB,GACtB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACL,eAAe,EACf,cAAc,EACd,KAAK,kBAAkB,GACxB,MAAM,uCAAuC,CAAC;AAE/C,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
+ {"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,4CAA4C;AAC5C,OAAO,EACL,YAAY,EACZ,WAAW,GAEZ,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EACL,aAAa,EACb,YAAY,GAEb,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACL,eAAe,EACf,cAAc,GAEf,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAGhE,oDAAoD;AACpD,OAAO,EACL,iBAAiB,GAElB,MAAM,0CAA0C,CAAC","sourcesContent":["// Legacy exports for backward compatibility\nexport {\n UserProvider,\n UserContext,\n type UserContextType,\n} from \"@/shared/providers/UserProvider.js\";\n\nexport {\n TokenProvider,\n TokenContext,\n type TokenContextType,\n} from \"@/shared/providers/TokenProvider.js\";\n\nexport {\n SessionProvider,\n SessionContext,\n type SessionContextType,\n} from \"@/shared/providers/SessionProvider.js\";\n\nexport { 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
+ {"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,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,iDAAiD,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC"}
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shared/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,iDAAiD,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC","sourcesContent":["export { useToken } from \"@/shared/hooks/useToken.js\";\nexport { useSession } from \"@/shared/hooks/useSession.js\";\nexport { useCivicAuthConfig } from \"@/shared/hooks/useCivicAuthConfig.js\";\nexport { useOAuthEndpoints } from \"@/shared/hooks/useOAuthEndpoints.js\";\nexport { useCurrentUrl } from \"@/shared/hooks/useCurrentUrl.js\";\nexport { useClientTokenExchangeSession } from \"@/shared/hooks/useClientTokenExchangeSession.js\";\nexport { useWindowFocused } from \"@/shared/hooks/useWindowFocused.js\";\nexport { useBfcacheHandler } from \"@/shared/hooks/useBfcacheHandler.js\";\n\nexport { useAuthStatus } from \"@/shared/providers/AuthStatusContext.js\";\n"]}
1
+ {"version":3,"file":"index.js","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","sourcesContent":["export { useBfcacheHandler } from \"@/shared/hooks/useBfcacheHandler.js\";\n\nexport { useAuthStatus } from \"@/shared/providers/AuthStatusContext.js\";\n"]}
@@ -0,0 +1,6 @@
1
+ import type { SessionData } from "../../types.js";
2
+ declare const useRefresh: (session: SessionData | null) => {
3
+ error: Error | undefined;
4
+ };
5
+ export { useRefresh };
6
+ //# sourceMappingURL=useRefresh.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRefresh.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/useRefresh.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9C,QAAA,MAAM,UAAU,YAAa,WAAW,GAAG,IAAI;;CAiD9C,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { useEffect, useMemo, useState } from "react";
2
+ import { useCivicAuthConfig } from "./useCivicAuthConfig.js";
3
+ import { LocalStorageAdapter } from "../../browser/storage.js";
4
+ import { BrowserAuthenticationRefresher } from "../lib/BrowserAuthenticationRefresher.js";
5
+ const useRefresh = (session) => {
6
+ const authConfig = useCivicAuthConfig();
7
+ const storage = useMemo(() => new LocalStorageAdapter(), []);
8
+ const [error, setError] = useState();
9
+ // setup token autorefresh
10
+ const [refresher, setRefresher] = useState(undefined);
11
+ useEffect(() => {
12
+ if (!authConfig)
13
+ return;
14
+ const abortController = new AbortController();
15
+ const currentRefresher = refresher;
16
+ const onError = async (error) => {
17
+ console.error("Error refreshing token", error);
18
+ refresher?.clearAutorefresh();
19
+ setError(error);
20
+ };
21
+ BrowserAuthenticationRefresher.build({ ...authConfig }, storage, onError).then((newRefresher) => {
22
+ if (abortController.signal.aborted)
23
+ return;
24
+ currentRefresher?.clearAutorefresh();
25
+ setRefresher(newRefresher);
26
+ });
27
+ return () => {
28
+ abortController.abort();
29
+ currentRefresher?.clearAutorefresh();
30
+ };
31
+ // eslint-disable-next-line react-hooks/exhaustive-deps
32
+ }, [authConfig, storage]); // Only depend on what actually changes
33
+ useEffect(() => {
34
+ if (session?.authenticated) {
35
+ refresher?.setupAutorefresh();
36
+ }
37
+ else {
38
+ refresher?.clearAutorefresh();
39
+ }
40
+ return () => refresher?.clearAutorefresh();
41
+ }, [refresher, session?.authenticated]);
42
+ return {
43
+ error,
44
+ };
45
+ };
46
+ export { useRefresh };
47
+ //# sourceMappingURL=useRefresh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRefresh.js","sourceRoot":"","sources":["../../../src/shared/hooks/useRefresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,8BAA8B,EAAE,MAAM,0CAA0C,CAAC;AAE1F,MAAM,UAAU,GAAG,CAAC,OAA2B,EAAE,EAAE;IACjD,MAAM,UAAU,GAAG,kBAAkB,EAAE,CAAC;IACxC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,EAAE,EAAE,EAAE,CAAC,CAAC;IAC7D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAS,CAAC;IAC5C,0BAA0B;IAC1B,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAExC,SAAS,CAAC,CAAC;IAEb,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,UAAU;YAAE,OAAO;QACxB,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QAC9C,MAAM,gBAAgB,GAAG,SAAS,CAAC;QAEnC,MAAM,OAAO,GAAG,KAAK,EAAE,KAAY,EAAE,EAAE;YACrC,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;YAC/C,SAAS,EAAE,gBAAgB,EAAE,CAAC;YAC9B,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC,CAAC;QACF,8BAA8B,CAAC,KAAK,CAClC,EAAE,GAAG,UAAU,EAAE,EACjB,OAAO,EACP,OAAO,CACR,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE;YACtB,IAAI,eAAe,CAAC,MAAM,CAAC,OAAO;gBAAE,OAAO;YAE3C,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;YACrC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,eAAe,CAAC,KAAK,EAAE,CAAC;YACxB,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;QACvC,CAAC,CAAC;QACF,uDAAuD;IACzD,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,uCAAuC;IAElE,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,EAAE,aAAa,EAAE,CAAC;YAC3B,SAAS,EAAE,gBAAgB,EAAE,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,SAAS,EAAE,gBAAgB,EAAE,CAAC;QAChC,CAAC;QAED,OAAO,GAAG,EAAE,CAAC,SAAS,EAAE,gBAAgB,EAAE,CAAC;IAC7C,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;IACxC,OAAO;QACL,KAAK;KACN,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import { useEffect, useMemo, useState } from \"react\";\nimport { useCivicAuthConfig } from \"./useCivicAuthConfig.js\";\nimport type { SessionData } from \"@/types.js\";\nimport { LocalStorageAdapter } from \"@/browser/storage.js\";\nimport { BrowserAuthenticationRefresher } from \"../lib/BrowserAuthenticationRefresher.js\";\n\nconst useRefresh = (session: SessionData | null) => {\n const authConfig = useCivicAuthConfig();\n const storage = useMemo(() => new LocalStorageAdapter(), []);\n const [error, setError] = useState<Error>();\n // setup token autorefresh\n const [refresher, setRefresher] = useState<\n BrowserAuthenticationRefresher | undefined\n >(undefined);\n\n useEffect(() => {\n if (!authConfig) return;\n const abortController = new AbortController();\n const currentRefresher = refresher;\n\n const onError = async (error: Error) => {\n console.error(\"Error refreshing token\", error);\n refresher?.clearAutorefresh();\n setError(error);\n };\n BrowserAuthenticationRefresher.build(\n { ...authConfig },\n storage,\n onError,\n ).then((newRefresher) => {\n if (abortController.signal.aborted) return;\n\n currentRefresher?.clearAutorefresh();\n setRefresher(newRefresher);\n });\n\n return () => {\n abortController.abort();\n currentRefresher?.clearAutorefresh();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [authConfig, storage]); // Only depend on what actually changes\n\n useEffect(() => {\n if (session?.authenticated) {\n refresher?.setupAutorefresh();\n } else {\n refresher?.clearAutorefresh();\n }\n\n return () => refresher?.clearAutorefresh();\n }, [refresher, session?.authenticated]);\n return {\n error,\n };\n};\n\nexport { useRefresh };\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "@civic/auth:0.11.2-beta.0";
1
+ export declare const VERSION = "@civic/auth:0.11.3-alpha.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,8BAA8B,CAAC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,+BAA+B,CAAC"}
@@ -1,3 +1,3 @@
1
1
  // This is an auto-generated file. Do not edit.
2
- export const VERSION = "@civic/auth:0.11.2-beta.0";
2
+ export const VERSION = "@civic/auth:0.11.3-alpha.0";
3
3
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,MAAM,CAAC,MAAM,OAAO,GAAG,2BAA2B,CAAC","sourcesContent":["// This is an auto-generated file. Do not edit.\n\nexport const VERSION = \"@civic/auth:0.11.2-beta.0\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,MAAM,CAAC,MAAM,OAAO,GAAG,4BAA4B,CAAC","sourcesContent":["// This is an auto-generated file. Do not edit.\n\nexport const VERSION = \"@civic/auth:0.11.3-alpha.0\";\n"]}