@civic/auth 0.11.3-alpha.1 → 0.11.3-beta.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 +1 -0
- package/dist/reactjs/core/GlobalAuthManager.d.ts.map +1 -1
- package/dist/reactjs/core/GlobalAuthManager.js +0 -3
- package/dist/reactjs/core/GlobalAuthManager.js.map +1 -1
- 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/package.json +3 -3
- package/dist/nextjs/NextClientAuthenticationRefresher.d.ts +0 -8
- package/dist/nextjs/NextClientAuthenticationRefresher.d.ts.map +0 -1
- package/dist/nextjs/NextClientAuthenticationRefresher.js +0 -24
- package/dist/nextjs/NextClientAuthenticationRefresher.js.map +0 -1
- package/dist/nextjs/NextServerAuthenticationRefresherImpl.d.ts +0 -12
- package/dist/nextjs/NextServerAuthenticationRefresherImpl.d.ts.map +0 -1
- package/dist/nextjs/NextServerAuthenticationRefresherImpl.js +0 -25
- package/dist/nextjs/NextServerAuthenticationRefresherImpl.js.map +0 -1
- package/dist/nextjs/hooks/useRefresh.d.ts +0 -5
- package/dist/nextjs/hooks/useRefresh.d.ts.map +0 -1
- package/dist/nextjs/hooks/useRefresh.js +0 -57
- package/dist/nextjs/hooks/useRefresh.js.map +0 -1
- package/dist/react-router-7/auth-loader.d.ts +0 -18
- package/dist/react-router-7/auth-loader.d.ts.map +0 -1
- package/dist/react-router-7/auth-loader.js +0 -36
- package/dist/react-router-7/auth-loader.js.map +0 -1
- package/dist/reactjs/providers/CivicAuthContext.d.ts +0 -44
- package/dist/reactjs/providers/CivicAuthContext.d.ts.map +0 -1
- package/dist/reactjs/providers/CivicAuthContext.js +0 -313
- package/dist/reactjs/providers/CivicAuthContext.js.map +0 -1
- package/dist/shared/hooks/useCivicAuthConfig.d.ts +0 -3
- package/dist/shared/hooks/useCivicAuthConfig.d.ts.map +0 -1
- package/dist/shared/hooks/useCivicAuthConfig.js +0 -10
- package/dist/shared/hooks/useCivicAuthConfig.js.map +0 -1
- package/dist/shared/hooks/useClientTokenExchangeSession.d.ts +0 -7
- package/dist/shared/hooks/useClientTokenExchangeSession.d.ts.map +0 -1
- package/dist/shared/hooks/useClientTokenExchangeSession.js +0 -17
- package/dist/shared/hooks/useClientTokenExchangeSession.js.map +0 -1
- package/dist/shared/hooks/useCurrentUrl.d.ts +0 -3
- package/dist/shared/hooks/useCurrentUrl.d.ts.map +0 -1
- package/dist/shared/hooks/useCurrentUrl.js +0 -24
- package/dist/shared/hooks/useCurrentUrl.js.map +0 -1
- package/dist/shared/hooks/useOAuthEndpoints.d.ts +0 -4
- package/dist/shared/hooks/useOAuthEndpoints.d.ts.map +0 -1
- package/dist/shared/hooks/useOAuthEndpoints.js +0 -14
- package/dist/shared/hooks/useOAuthEndpoints.js.map +0 -1
- package/dist/shared/hooks/useRefresh.d.ts +0 -6
- package/dist/shared/hooks/useRefresh.d.ts.map +0 -1
- package/dist/shared/hooks/useRefresh.js +0 -47
- package/dist/shared/hooks/useRefresh.js.map +0 -1
- package/dist/shared/hooks/useSession.d.ts +0 -3
- package/dist/shared/hooks/useSession.d.ts.map +0 -1
- package/dist/shared/hooks/useSession.js +0 -13
- package/dist/shared/hooks/useSession.js.map +0 -1
- package/dist/shared/hooks/useToken.d.ts +0 -3
- package/dist/shared/hooks/useToken.d.ts.map +0 -1
- package/dist/shared/hooks/useToken.js +0 -12
- package/dist/shared/hooks/useToken.js.map +0 -1
- package/dist/shared/hooks/useWindowFocused.d.ts +0 -5
- package/dist/shared/hooks/useWindowFocused.d.ts.map +0 -1
- package/dist/shared/hooks/useWindowFocused.js +0 -21
- package/dist/shared/hooks/useWindowFocused.js.map +0 -1
- package/dist/shared/providers/CivicAuthConfigContext.d.ts +0 -25
- package/dist/shared/providers/CivicAuthConfigContext.d.ts.map +0 -1
- package/dist/shared/providers/CivicAuthConfigContext.js +0 -66
- package/dist/shared/providers/CivicAuthConfigContext.js.map +0 -1
- package/dist/shared/providers/SessionProvider.d.ts +0 -19
- package/dist/shared/providers/SessionProvider.d.ts.map +0 -1
- package/dist/shared/providers/SessionProvider.js +0 -25
- package/dist/shared/providers/SessionProvider.js.map +0 -1
- package/dist/shared/providers/TokenProvider.d.ts +0 -17
- package/dist/shared/providers/TokenProvider.d.ts.map +0 -1
- package/dist/shared/providers/TokenProvider.js +0 -31
- package/dist/shared/providers/TokenProvider.js.map +0 -1
- package/dist/shared/providers/UserProvider.d.ts +0 -26
- package/dist/shared/providers/UserProvider.d.ts.map +0 -1
- package/dist/shared/providers/UserProvider.js +0 -64
- package/dist/shared/providers/UserProvider.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,313 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,I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ACP,yBAAyB;QACzB,iBAAiB;QACjB,iBAAiB;QACjB,WAAW;KACZ,CAAC,EACF;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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCivicAuthConfig.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/useCivicAuthConfig.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,kBAAkB,uCAGvB,CAAC;AAEF,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useContext } from "react";
|
|
3
|
-
import { CivicAuthConfigContext } from "../../shared/providers/CivicAuthConfigContext.js";
|
|
4
|
-
// TokenProvider will use this internal context to access Config
|
|
5
|
-
const useCivicAuthConfig = () => {
|
|
6
|
-
const context = useContext(CivicAuthConfigContext);
|
|
7
|
-
return context;
|
|
8
|
-
};
|
|
9
|
-
export { useCivicAuthConfig };
|
|
10
|
-
//# sourceMappingURL=useCivicAuthConfig.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCivicAuthConfig.js","sourceRoot":"","sources":["../../../src/shared/hooks/useCivicAuthConfig.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAC;AAEtF,gEAAgE;AAChE,MAAM,kBAAkB,GAAG,GAAG,EAAE;IAC9B,MAAM,OAAO,GAAG,UAAU,CAAC,sBAAsB,CAAC,CAAC;IACnD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,OAAO,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["\"use client\";\nimport { useContext } from \"react\";\nimport { CivicAuthConfigContext } from \"@/shared/providers/CivicAuthConfigContext.js\";\n\n// TokenProvider will use this internal context to access Config\nconst useCivicAuthConfig = () => {\n const context = useContext(CivicAuthConfigContext);\n return context;\n};\n\nexport { useCivicAuthConfig };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useClientTokenExchangeSession.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/useClientTokenExchangeSession.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,6BAA6B;;;;4BAMR,MAAM;CAIvC,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
// This hook was part of the old ReactJS token exchange system
|
|
3
|
-
// It's kept here to maintain compatibility with shared components
|
|
4
|
-
// that haven't been updated to use the VanillaJS core.
|
|
5
|
-
// It's deprecated and will be removed in a future version.
|
|
6
|
-
export const useClientTokenExchangeSession = () => {
|
|
7
|
-
return {
|
|
8
|
-
data: null,
|
|
9
|
-
error: null,
|
|
10
|
-
isLoading: false,
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Parameter is required for API compatibility but not used since functionality is now in VanillaJS core
|
|
12
|
-
doTokenExchange: async (_url) => {
|
|
13
|
-
// Do nothing - this functionality is now handled by VanillaJS core
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=useClientTokenExchangeSession.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useClientTokenExchangeSession.js","sourceRoot":"","sources":["../../../src/shared/hooks/useClientTokenExchangeSession.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,8DAA8D;AAC9D,kEAAkE;AAClE,uDAAuD;AACvD,2DAA2D;AAC3D,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,EAAE;IAChD,OAAO;QACL,IAAI,EAAE,IAAI;QACV,KAAK,EAAE,IAAI;QACX,SAAS,EAAE,KAAK;QAChB,sKAAsK;QACtK,eAAe,EAAE,KAAK,EAAE,IAAY,EAAE,EAAE;YACtC,mEAAmE;QACrE,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["\"use client\";\n\n// This hook was part of the old ReactJS token exchange system\n// It's kept here to maintain compatibility with shared components\n// that haven't been updated to use the VanillaJS core.\n// It's deprecated and will be removed in a future version.\nexport const useClientTokenExchangeSession = () => {\n return {\n data: null,\n error: null,\n isLoading: false,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Parameter is required for API compatibility but not used since functionality is now in VanillaJS core\n doTokenExchange: async (_url: string) => {\n // Do nothing - this functionality is now handled by VanillaJS core\n },\n };\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrentUrl.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/useCurrentUrl.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,aAAa,0BAuBlB,CAAC;AACF,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
const useCurrentUrl = () => {
|
|
3
|
-
const [currentUrl, setCurrentUrl] = useState();
|
|
4
|
-
// update the current url when the url changes
|
|
5
|
-
useEffect(() => {
|
|
6
|
-
const handleUrlChange = () => {
|
|
7
|
-
setCurrentUrl(window.location.href);
|
|
8
|
-
};
|
|
9
|
-
window.addEventListener("popstate", handleUrlChange);
|
|
10
|
-
window.addEventListener("pushstate", handleUrlChange);
|
|
11
|
-
window.addEventListener("replacestate", handleUrlChange);
|
|
12
|
-
handleUrlChange();
|
|
13
|
-
return () => {
|
|
14
|
-
if (typeof window !== "undefined") {
|
|
15
|
-
window.removeEventListener("popstate", handleUrlChange);
|
|
16
|
-
window.removeEventListener("pushstate", handleUrlChange);
|
|
17
|
-
window.removeEventListener("replacestate", handleUrlChange);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}, []);
|
|
21
|
-
return currentUrl;
|
|
22
|
-
};
|
|
23
|
-
export { useCurrentUrl };
|
|
24
|
-
//# sourceMappingURL=useCurrentUrl.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrentUrl.js","sourceRoot":"","sources":["../../../src/shared/hooks/useCurrentUrl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,EAAsB,CAAC;IACnE,8CAA8C;IAC9C,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,eAAe,GAAG,GAAG,EAAE;YAC3B,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACtC,CAAC,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;QACrD,MAAM,CAAC,gBAAgB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;QACtD,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;QAEzD,eAAe,EAAE,CAAC;QAElB,OAAO,GAAG,EAAE;YACV,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;gBAClC,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;gBACxD,MAAM,CAAC,mBAAmB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;gBACzD,MAAM,CAAC,mBAAmB,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AACF,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import { useEffect, useState } from \"react\";\n\nconst useCurrentUrl = () => {\n const [currentUrl, setCurrentUrl] = useState<string | undefined>();\n // update the current url when the url changes\n useEffect(() => {\n const handleUrlChange = () => {\n setCurrentUrl(window.location.href);\n };\n window.addEventListener(\"popstate\", handleUrlChange);\n window.addEventListener(\"pushstate\", handleUrlChange);\n window.addEventListener(\"replacestate\", handleUrlChange);\n\n handleUrlChange();\n\n return () => {\n if (typeof window !== \"undefined\") {\n window.removeEventListener(\"popstate\", handleUrlChange);\n window.removeEventListener(\"pushstate\", handleUrlChange);\n window.removeEventListener(\"replacestate\", handleUrlChange);\n }\n };\n }, []);\n\n return currentUrl;\n};\nexport { useCurrentUrl };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useOAuthEndpoints.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/useOAuthEndpoints.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C,QAAA,MAAM,iBAAiB,iBAAkB,MAAM,qBAW9C,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_AUTH_SERVER } from "../../constants.js";
|
|
2
|
-
import { getOauthEndpoints } from "../../lib/oauth.js";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
|
-
const useOAuthEndpoints = (oauthServer) => {
|
|
5
|
-
const [endpoints, setEndpoints] = useState(null);
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
getOauthEndpoints(oauthServer || DEFAULT_AUTH_SERVER).then((retrievedEndpoints) => {
|
|
8
|
-
setEndpoints(retrievedEndpoints);
|
|
9
|
-
});
|
|
10
|
-
}, [oauthServer]);
|
|
11
|
-
return endpoints;
|
|
12
|
-
};
|
|
13
|
-
export { useOAuthEndpoints };
|
|
14
|
-
//# sourceMappingURL=useOAuthEndpoints.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useOAuthEndpoints.js","sourceRoot":"","sources":["../../../src/shared/hooks/useOAuthEndpoints.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,MAAM,iBAAiB,GAAG,CAAC,WAAoB,EAAE,EAAE;IACjD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAmB,IAAI,CAAC,CAAC;IACnE,SAAS,CAAC,GAAG,EAAE;QACb,iBAAiB,CAAC,WAAW,IAAI,mBAAmB,CAAC,CAAC,IAAI,CACxD,CAAC,kBAAkB,EAAE,EAAE;YACrB,YAAY,CAAC,kBAAkB,CAAC,CAAC;QACnC,CAAC,CACF,CAAC;IACJ,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAElB,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import { DEFAULT_AUTH_SERVER } from \"@/constants.js\";\nimport { getOauthEndpoints } from \"@/lib/oauth.js\";\nimport type { Endpoints } from \"@/types.js\";\nimport { useEffect, useState } from \"react\";\n\nconst useOAuthEndpoints = (oauthServer?: string) => {\n const [endpoints, setEndpoints] = useState<Endpoints | null>(null);\n useEffect(() => {\n getOauthEndpoints(oauthServer || DEFAULT_AUTH_SERVER).then(\n (retrievedEndpoints) => {\n setEndpoints(retrievedEndpoints);\n },\n );\n }, [oauthServer]);\n\n return endpoints;\n};\n\nexport { useOAuthEndpoints };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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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AO,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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSession.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/useSession.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,UAAU,6EAMf,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useContext } from "react";
|
|
3
|
-
import { SessionContext } from "../../shared/providers/SessionProvider.js";
|
|
4
|
-
// TokenProvider will use this internal context to access session
|
|
5
|
-
const useSession = () => {
|
|
6
|
-
const context = useContext(SessionContext);
|
|
7
|
-
if (!context) {
|
|
8
|
-
throw new Error("useSession must be used within an SessionProvider");
|
|
9
|
-
}
|
|
10
|
-
return context;
|
|
11
|
-
};
|
|
12
|
-
export { useSession };
|
|
13
|
-
//# sourceMappingURL=useSession.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSession.js","sourceRoot":"","sources":["../../../src/shared/hooks/useSession.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAEvE,iEAAiE;AACjE,MAAM,UAAU,GAAG,GAAG,EAAE;IACtB,MAAM,OAAO,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC;IAC3C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["\"use client\";\nimport { useContext } from \"react\";\nimport { SessionContext } from \"@/shared/providers/SessionProvider.js\";\n\n// TokenProvider will use this internal context to access session\nconst useSession = () => {\n const context = useContext(SessionContext);\n if (!context) {\n throw new Error(\"useSession must be used within an SessionProvider\");\n }\n return context;\n};\n\nexport { useSession };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToken.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/useToken.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,QAAQ,sEAQb,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useContext } from "react";
|
|
3
|
-
import { TokenContext } from "../../shared/providers/TokenProvider.js";
|
|
4
|
-
const useToken = () => {
|
|
5
|
-
const context = useContext(TokenContext);
|
|
6
|
-
if (!context) {
|
|
7
|
-
throw new Error("useToken must be used within a TokenProvider");
|
|
8
|
-
}
|
|
9
|
-
return context;
|
|
10
|
-
};
|
|
11
|
-
export { useToken };
|
|
12
|
-
//# sourceMappingURL=useToken.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useToken.js","sourceRoot":"","sources":["../../../src/shared/hooks/useToken.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAEnE,MAAM,QAAQ,GAAG,GAAG,EAAE;IACpB,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAEzC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAC","sourcesContent":["\"use client\";\nimport { useContext } from \"react\";\nimport { TokenContext } from \"@/shared/providers/TokenProvider.js\";\n\nconst useToken = () => {\n const context = useContext(TokenContext);\n\n if (!context) {\n throw new Error(\"useToken must be used within a TokenProvider\");\n }\n\n return context;\n};\n\nexport { useToken };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowFocused.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/useWindowFocused.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,gBAAgB;;CAmBrB,CAAC;AACF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|