@civic/auth 0.0.1-beta.15 → 0.0.1-beta.17
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/dist/{chunk-3Q3CWGPG.mjs → chunk-5XL2ST72.mjs} +45 -14
- package/dist/chunk-5XL2ST72.mjs.map +1 -0
- package/dist/{chunk-EDLPS3AK.mjs → chunk-G3P5TIO2.mjs} +3 -1
- package/dist/chunk-G3P5TIO2.mjs.map +1 -0
- package/dist/{chunk-F2CKPLXX.js → chunk-RF23Q4V6.js} +4 -2
- package/dist/chunk-RF23Q4V6.js.map +1 -0
- package/dist/{chunk-F55XKBNM.js → chunk-SEKF2WZX.js} +50 -19
- package/dist/chunk-SEKF2WZX.js.map +1 -0
- package/dist/{index-Bq3T3FPG.d.ts → index-DTimUlkB.d.ts} +2 -1
- package/dist/{index-GtnyFGD2.d.mts → index-DvjkKpkk.d.mts} +2 -1
- package/dist/index.css +2 -6
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/nextjs.d.mts +3 -9
- package/dist/nextjs.d.ts +3 -9
- package/dist/nextjs.js +29 -24
- package/dist/nextjs.js.map +1 -1
- package/dist/nextjs.mjs +10 -5
- package/dist/nextjs.mjs.map +1 -1
- package/dist/react.d.mts +16 -10
- package/dist/react.d.ts +16 -10
- package/dist/react.js +156 -92
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +174 -110
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +2 -2
- package/dist/server.mjs +1 -1
- package/dist/{types-Bfi0hVMZ.d.mts → types-HdCjGldB.d.mts} +2 -2
- package/dist/{types-Bfi0hVMZ.d.ts → types-HdCjGldB.d.ts} +2 -2
- package/dist/types-b4c1koXj.d.mts +19 -0
- package/dist/types-b4c1koXj.d.ts +19 -0
- package/package.json +3 -3
- package/dist/chunk-3Q3CWGPG.mjs.map +0 -1
- package/dist/chunk-EDLPS3AK.mjs.map +0 -1
- package/dist/chunk-F2CKPLXX.js.map +0 -1
- package/dist/chunk-F55XKBNM.js.map +0 -1
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { U as UserContextType, A as AuthContextType } from './index-
|
|
2
|
-
import { F as ForwardedTokens, C as Config, S as SessionData, D as DisplayMode } from './types-
|
|
1
|
+
import { U as UserContextType, A as AuthContextType } from './index-DTimUlkB.js';
|
|
2
|
+
import { F as ForwardedTokens, C as Config, S as SessionData, b as EmptyObject, U as User, D as DisplayMode } from './types-HdCjGldB.js';
|
|
3
|
+
import { O as OAuthTokens } from './types-b4c1koXj.js';
|
|
3
4
|
import { ReactNode, RefObject, Dispatch, SetStateAction } from 'react';
|
|
4
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
6
|
import 'oslo/jwt';
|
|
@@ -28,11 +29,7 @@ type AuthProviderProps = {
|
|
|
28
29
|
onSignOut?: () => void;
|
|
29
30
|
pkceConsumer?: PKCEConsumer;
|
|
30
31
|
modalIframe?: boolean;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
type SessionProviderOutput = SessionData & {
|
|
34
|
-
iframeRef: RefObject<HTMLIFrameElement> | null;
|
|
35
|
-
setAuthResponseUrl: Dispatch<SetStateAction<string | null>>;
|
|
32
|
+
sessionData?: SessionData;
|
|
36
33
|
};
|
|
37
34
|
|
|
38
35
|
type CivicAuthProviderProps = Omit<AuthProviderProps, "pkceConsumer">;
|
|
@@ -43,13 +40,13 @@ declare const CivicNextAuthProvider: ({ children, ...props }: NextCivicAuthProvi
|
|
|
43
40
|
|
|
44
41
|
declare const useUser: <T extends Record<string, unknown> = Record<string, never>>() => UserContextType<T>;
|
|
45
42
|
|
|
46
|
-
declare const useUserCookie: () =>
|
|
43
|
+
declare const useUserCookie: <T extends EmptyObject>() => User<T> | null;
|
|
47
44
|
|
|
48
45
|
declare const useToken: () => TokenContextType;
|
|
49
46
|
|
|
50
47
|
declare const useAuth: () => AuthContextType;
|
|
51
48
|
|
|
52
|
-
declare const useSession: () =>
|
|
49
|
+
declare const useSession: () => SessionData;
|
|
53
50
|
|
|
54
51
|
type ConfigProviderOutput = {
|
|
55
52
|
config: Config;
|
|
@@ -60,6 +57,15 @@ type ConfigProviderOutput = {
|
|
|
60
57
|
|
|
61
58
|
declare const useConfig: () => ConfigProviderOutput;
|
|
62
59
|
|
|
60
|
+
declare const useTokenCookie: (tokenName: OAuthTokens) => string | null;
|
|
61
|
+
|
|
62
|
+
type IframeProviderOutput = {
|
|
63
|
+
iframeRef: RefObject<HTMLIFrameElement> | null;
|
|
64
|
+
setAuthResponseUrl: Dispatch<SetStateAction<string | null>>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
declare const useIframe: () => IframeProviderOutput;
|
|
68
|
+
|
|
63
69
|
type CivicAuthIframeContainerProps = {
|
|
64
70
|
onClose?: () => void;
|
|
65
71
|
closeOnRedirect?: boolean;
|
|
@@ -84,4 +90,4 @@ declare const NextLogOut: ({ children }: {
|
|
|
84
90
|
children: ReactNode;
|
|
85
91
|
}) => react_jsx_runtime.JSX.Element;
|
|
86
92
|
|
|
87
|
-
export { AuthContextType, CivicAuthIframeContainer, CivicAuthProvider, type CivicAuthProviderProps, CivicNextAuthProvider, type NextCivicAuthProviderProps, NextLogOut, SignInButton, SignOutButton, type TokenContextType, UserButton, UserContextType, useAuth, useConfig, useSession, useToken, useUser, useUserCookie };
|
|
93
|
+
export { AuthContextType, CivicAuthIframeContainer, CivicAuthProvider, type CivicAuthProviderProps, CivicNextAuthProvider, type NextCivicAuthProviderProps, NextLogOut, SignInButton, SignOutButton, type TokenContextType, UserButton, UserContextType, useAuth, useConfig, useIframe, useSession, useToken, useTokenCookie, useUser, useUserCookie };
|
package/dist/react.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkSEKF2WZXjs = require('./chunk-SEKF2WZX.js');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
@@ -17,7 +17,8 @@ var _chunkF55XKBNMjs = require('./chunk-F55XKBNM.js');
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
var _chunkRF23Q4V6js = require('./chunk-RF23Q4V6.js');
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
|
|
@@ -60,31 +61,15 @@ var useAuth = () => {
|
|
|
60
61
|
|
|
61
62
|
// src/react/providers/SessionProvider.tsx
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
64
|
var _jsxruntime = require('react/jsx-runtime');
|
|
66
65
|
var defaultSession = {
|
|
67
66
|
authenticated: false,
|
|
68
67
|
idToken: void 0,
|
|
69
68
|
accessToken: void 0,
|
|
70
|
-
displayMode: "iframe"
|
|
71
|
-
iframeRef: null,
|
|
72
|
-
setAuthResponseUrl: () => {
|
|
73
|
-
}
|
|
69
|
+
displayMode: "iframe"
|
|
74
70
|
};
|
|
75
71
|
var SessionContext = _react.createContext.call(void 0, defaultSession);
|
|
76
|
-
var SessionProvider = ({
|
|
77
|
-
children,
|
|
78
|
-
session,
|
|
79
|
-
iframeRef,
|
|
80
|
-
setAuthResponseUrl
|
|
81
|
-
}) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
82
|
-
SessionContext.Provider,
|
|
83
|
-
{
|
|
84
|
-
value: _chunkCRTRMMJ7js.__spreadProps.call(void 0, _chunkCRTRMMJ7js.__spreadValues.call(void 0, {}, session || defaultSession), { iframeRef, setAuthResponseUrl }),
|
|
85
|
-
children
|
|
86
|
-
}
|
|
87
|
-
);
|
|
72
|
+
var SessionProvider = ({ children, session }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SessionContext.Provider, { value: _chunkCRTRMMJ7js.__spreadValues.call(void 0, _chunkCRTRMMJ7js.__spreadValues.call(void 0, {}, defaultSession), session || {}), children });
|
|
88
73
|
|
|
89
74
|
// src/react/hooks/useSession.tsx
|
|
90
75
|
var useSession = () => {
|
|
@@ -116,7 +101,7 @@ var TokenProvider = ({ children }) => {
|
|
|
116
101
|
const parsedJWT = _jwt.parseJWT.call(void 0, session.idToken);
|
|
117
102
|
if (!parsedJWT) return null;
|
|
118
103
|
const { forwardedTokens } = parsedJWT.payload;
|
|
119
|
-
return forwardedTokens ?
|
|
104
|
+
return forwardedTokens ? _chunkRF23Q4V6js.convertForwardedTokenFormat.call(void 0, forwardedTokens) : null;
|
|
120
105
|
}, [session == null ? void 0 : session.idToken]);
|
|
121
106
|
const value = _react.useMemo.call(void 0,
|
|
122
107
|
() => ({
|
|
@@ -167,7 +152,7 @@ var UserProvider = ({
|
|
|
167
152
|
if (!accessToken) {
|
|
168
153
|
return null;
|
|
169
154
|
}
|
|
170
|
-
const userSession = new (0,
|
|
155
|
+
const userSession = new (0, _chunkRF23Q4V6js.GenericUserSession)(storage);
|
|
171
156
|
return userSession.get();
|
|
172
157
|
});
|
|
173
158
|
const {
|
|
@@ -272,9 +257,9 @@ var CivicAuthIframe = _react.forwardRef.call(void 0,
|
|
|
272
257
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
273
258
|
"iframe",
|
|
274
259
|
{
|
|
275
|
-
id:
|
|
260
|
+
id: _chunkRF23Q4V6js.IFRAME_ID,
|
|
276
261
|
ref,
|
|
277
|
-
className: "cac-h-
|
|
262
|
+
className: "cac-h-[26rem] cac-w-80 cac-border-none",
|
|
278
263
|
onLoad
|
|
279
264
|
}
|
|
280
265
|
);
|
|
@@ -287,7 +272,7 @@ CivicAuthIframe.displayName = "CivicAuthIframe";
|
|
|
287
272
|
function NoChrome({
|
|
288
273
|
children
|
|
289
274
|
}) {
|
|
290
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
275
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "cac-relative", children });
|
|
291
276
|
}
|
|
292
277
|
function IframeChrome({
|
|
293
278
|
children,
|
|
@@ -327,7 +312,7 @@ var CivicAuthIframeContainer = ({
|
|
|
327
312
|
const [isLoading, setIsLoading] = _react.useState.call(void 0, true);
|
|
328
313
|
const { isLoading: isAuthLoading } = useAuth();
|
|
329
314
|
const config = useConfig();
|
|
330
|
-
const { setAuthResponseUrl, iframeRef } =
|
|
315
|
+
const { setAuthResponseUrl, iframeRef } = useIframe();
|
|
331
316
|
const processIframeUrl = _react.useCallback.call(void 0, () => {
|
|
332
317
|
if (iframeRef && iframeRef.current && iframeRef.current.contentWindow) {
|
|
333
318
|
try {
|
|
@@ -335,9 +320,9 @@ var CivicAuthIframeContainer = ({
|
|
|
335
320
|
if (iframeUrl.startsWith(config.redirectUrl)) {
|
|
336
321
|
setIsLoading(true);
|
|
337
322
|
const iframeBody = iframeRef.current.contentWindow.document.body.innerHTML;
|
|
338
|
-
if (iframeBody.includes(
|
|
323
|
+
if (iframeBody.includes(_chunkRF23Q4V6js.TOKEN_EXCHANGE_TRIGGER_TEXT)) {
|
|
339
324
|
console.log(
|
|
340
|
-
|
|
325
|
+
`${_chunkRF23Q4V6js.TOKEN_EXCHANGE_TRIGGER_TEXT}, calling callback URL again...`
|
|
341
326
|
);
|
|
342
327
|
const params = new URL(iframeUrl).searchParams;
|
|
343
328
|
fetch(`${config.redirectUrl}?${params.toString()}`);
|
|
@@ -382,7 +367,7 @@ var CivicAuthIframeContainer = ({
|
|
|
382
367
|
const showLoadingIcon = isLoading || isAuthLoading || !((_a = iframeRef == null ? void 0 : iframeRef.current) == null ? void 0 : _a.getAttribute("src"));
|
|
383
368
|
const WrapperComponent = config.modalIframe ? IframeChrome : NoChrome;
|
|
384
369
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, WrapperComponent, { onClose, children: [
|
|
385
|
-
showLoadingIcon && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "cac-absolute cac-inset-0 cac-flex cac-items-center cac-justify-center cac-rounded-3xl cac-bg-
|
|
370
|
+
showLoadingIcon && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "cac-absolute cac-inset-0 cac-flex cac-items-center cac-justify-center cac-rounded-3xl cac-bg-white", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LoadingIcon, {}) }),
|
|
386
371
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, CivicAuthIframe, { ref: iframeRef, onLoad: handleIframeLoad })
|
|
387
372
|
] });
|
|
388
373
|
};
|
|
@@ -422,6 +407,23 @@ var ConfigProvider = ({
|
|
|
422
407
|
}
|
|
423
408
|
);
|
|
424
409
|
|
|
410
|
+
// src/react/providers/IframeProvider.tsx
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
var defaultIframe = {
|
|
416
|
+
iframeRef: null,
|
|
417
|
+
setAuthResponseUrl: () => {
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
var IframeContext = _react.createContext.call(void 0, defaultIframe);
|
|
421
|
+
var IframeProvider = ({
|
|
422
|
+
children,
|
|
423
|
+
iframeRef,
|
|
424
|
+
setAuthResponseUrl
|
|
425
|
+
}) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, IframeContext.Provider, { value: { iframeRef, setAuthResponseUrl }, children });
|
|
426
|
+
|
|
425
427
|
// src/shared/AuthProvider.tsx
|
|
426
428
|
|
|
427
429
|
var globalThisObject;
|
|
@@ -434,7 +436,7 @@ if (typeof window !== "undefined") {
|
|
|
434
436
|
}
|
|
435
437
|
globalThisObject.globalThis = globalThisObject;
|
|
436
438
|
function BlockDisplay({ children }) {
|
|
437
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "cac-
|
|
439
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "cac-relative cac-left-0 cac-top-0 cac-z-50 cac-flex cac-h-screen cac-w-screen cac-items-center cac-justify-center cac-bg-white", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "cac-absolute cac-inset-0 cac-flex cac-items-center cac-justify-center cac-bg-white", children }) });
|
|
438
440
|
}
|
|
439
441
|
var AuthProvider = ({
|
|
440
442
|
children,
|
|
@@ -445,7 +447,8 @@ var AuthProvider = ({
|
|
|
445
447
|
onSignOut,
|
|
446
448
|
pkceConsumer,
|
|
447
449
|
nonce,
|
|
448
|
-
modalIframe = true
|
|
450
|
+
modalIframe = true,
|
|
451
|
+
sessionData: inputSessionData
|
|
449
452
|
}) => {
|
|
450
453
|
const [iframeUrl, setIframeUrl] = _react.useState.call(void 0, null);
|
|
451
454
|
const [currentUrl, setCurrentUrl] = _react.useState.call(void 0, null);
|
|
@@ -458,11 +461,11 @@ var AuthProvider = ({
|
|
|
458
461
|
const [isRedirecting, setIsRedirecting] = _react.useState.call(void 0, false);
|
|
459
462
|
const queryClient3 = _reactquery.useQueryClient.call(void 0, );
|
|
460
463
|
const iframeRef = _react.useRef.call(void 0, null);
|
|
461
|
-
const serverTokenExchange = pkceConsumer instanceof
|
|
464
|
+
const serverTokenExchange = pkceConsumer instanceof _chunkRF23Q4V6js.ConfidentialClientPKCEConsumer;
|
|
462
465
|
_react.useEffect.call(void 0, () => {
|
|
463
466
|
if (typeof globalThis.window !== "undefined") {
|
|
464
467
|
setCurrentUrl(globalThis.window.location.href);
|
|
465
|
-
const isInIframeVal =
|
|
468
|
+
const isInIframeVal = _chunkRF23Q4V6js.isWindowInIframe.call(void 0, globalThis.window);
|
|
466
469
|
setIsInIframe(isInIframeVal);
|
|
467
470
|
}
|
|
468
471
|
}, []);
|
|
@@ -473,11 +476,11 @@ var AuthProvider = ({
|
|
|
473
476
|
const [authService, setAuthService] = _react.useState.call(void 0, );
|
|
474
477
|
_react.useEffect.call(void 0, () => {
|
|
475
478
|
if (!currentUrl) return;
|
|
476
|
-
|
|
479
|
+
_chunkRF23Q4V6js.BrowserAuthenticationService.build({
|
|
477
480
|
clientId,
|
|
478
481
|
redirectUrl,
|
|
479
482
|
oauthServer: config.oauthServer,
|
|
480
|
-
scopes:
|
|
483
|
+
scopes: _chunkRF23Q4V6js.DEFAULT_SCOPES,
|
|
481
484
|
displayMode
|
|
482
485
|
}).then(setAuthService);
|
|
483
486
|
}, [currentUrl, clientId, redirectUrl, config, displayMode]);
|
|
@@ -498,9 +501,16 @@ var AuthProvider = ({
|
|
|
498
501
|
if (!authService) {
|
|
499
502
|
return { authenticated: false };
|
|
500
503
|
}
|
|
504
|
+
if (inputSessionData) {
|
|
505
|
+
return inputSessionData;
|
|
506
|
+
}
|
|
501
507
|
const url = new URL(
|
|
502
508
|
authResponseUrl ? authResponseUrl : globalThis.window.location.href || ""
|
|
503
509
|
);
|
|
510
|
+
const existingSessionData = yield authService.validateExistingSession();
|
|
511
|
+
if (existingSessionData.authenticated) {
|
|
512
|
+
return existingSessionData;
|
|
513
|
+
}
|
|
504
514
|
const code = url.searchParams.get("code");
|
|
505
515
|
const state = url.searchParams.get("state");
|
|
506
516
|
if (!serverTokenExchange && code && state && !isInIframe) {
|
|
@@ -511,12 +521,12 @@ var AuthProvider = ({
|
|
|
511
521
|
state
|
|
512
522
|
});
|
|
513
523
|
yield authService.tokenExchange(code, state);
|
|
514
|
-
const clientStorage = new (0,
|
|
515
|
-
const user = yield
|
|
524
|
+
const clientStorage = new (0, _chunkRF23Q4V6js.LocalStorageAdapter)();
|
|
525
|
+
const user = yield _chunkRF23Q4V6js.getUser.call(void 0, clientStorage);
|
|
516
526
|
if (!user) {
|
|
517
527
|
throw new Error("Failed to get user info");
|
|
518
528
|
}
|
|
519
|
-
const userSession = new (0,
|
|
529
|
+
const userSession = new (0, _chunkRF23Q4V6js.GenericUserSession)(clientStorage);
|
|
520
530
|
userSession.set(user);
|
|
521
531
|
onSignIn == null ? void 0 : onSignIn();
|
|
522
532
|
return authService.getSessionData();
|
|
@@ -528,10 +538,6 @@ var AuthProvider = ({
|
|
|
528
538
|
return { authenticated: false };
|
|
529
539
|
}
|
|
530
540
|
}
|
|
531
|
-
const existingSessionData = yield authService.validateExistingSession();
|
|
532
|
-
if (existingSessionData.authenticated) {
|
|
533
|
-
return existingSessionData;
|
|
534
|
-
}
|
|
535
541
|
return existingSessionData;
|
|
536
542
|
})
|
|
537
543
|
});
|
|
@@ -564,13 +570,13 @@ var AuthProvider = ({
|
|
|
564
570
|
if (!pkceConsumer) {
|
|
565
571
|
return null;
|
|
566
572
|
}
|
|
567
|
-
return browserAuthenticationInitiator || new (0,
|
|
573
|
+
return browserAuthenticationInitiator || new (0, _chunkRF23Q4V6js.BrowserAuthenticationInitiator)({
|
|
568
574
|
pkceConsumer,
|
|
569
575
|
// generate and retrieve the challenge client-side
|
|
570
576
|
clientId,
|
|
571
577
|
redirectUrl,
|
|
572
|
-
state:
|
|
573
|
-
scopes:
|
|
578
|
+
state: _chunkRF23Q4V6js.generateState.call(void 0, useDisplayMode),
|
|
579
|
+
scopes: _chunkRF23Q4V6js.DEFAULT_SCOPES,
|
|
574
580
|
displayMode: useDisplayMode,
|
|
575
581
|
oauthServer: config.oauthServer,
|
|
576
582
|
// the endpoints to use for the login (if not obtained from the auth server
|
|
@@ -607,11 +613,7 @@ var AuthProvider = ({
|
|
|
607
613
|
() => session ? session.authenticated : false,
|
|
608
614
|
[session]
|
|
609
615
|
);
|
|
610
|
-
|
|
611
|
-
data: autoSignIn,
|
|
612
|
-
isLoading: autoSignInLoading,
|
|
613
|
-
error: autoSignInError
|
|
614
|
-
} = _reactquery.useQuery.call(void 0, {
|
|
616
|
+
_reactquery.useQuery.call(void 0, {
|
|
615
617
|
queryKey: ["autoSignIn", modalIframe, redirectUrl, isAuthenticated],
|
|
616
618
|
queryFn: () => _chunkCRTRMMJ7js.__async.call(void 0, void 0, null, function* () {
|
|
617
619
|
if (!modalIframe && redirectUrl && !isAuthenticated && iframeRef.current) {
|
|
@@ -641,12 +643,11 @@ var AuthProvider = ({
|
|
|
641
643
|
modalIframe,
|
|
642
644
|
serverTokenExchange,
|
|
643
645
|
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
644
|
-
|
|
646
|
+
IframeProvider,
|
|
645
647
|
{
|
|
646
|
-
session,
|
|
647
648
|
setAuthResponseUrl,
|
|
648
649
|
iframeRef,
|
|
649
|
-
children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, TokenProvider, { children: [
|
|
650
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SessionProvider, { session, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, TokenProvider, { children: [
|
|
650
651
|
modalIframe && !isInIframe && !(session == null ? void 0 : session.authenticated) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
651
652
|
"div",
|
|
652
653
|
{
|
|
@@ -659,13 +660,13 @@ var AuthProvider = ({
|
|
|
659
660
|
)
|
|
660
661
|
}
|
|
661
662
|
),
|
|
662
|
-
modalIframe && (isInIframe || isRedirecting || isLoading) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BlockDisplay, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LoadingIcon, {}) }),
|
|
663
|
+
modalIframe && (isInIframe || isRedirecting || isLoading && !serverTokenExchange) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BlockDisplay, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LoadingIcon, {}) }),
|
|
663
664
|
(tokenExchangeError || error) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BlockDisplay, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
|
|
664
665
|
"Error: ",
|
|
665
666
|
(tokenExchangeError || error).message
|
|
666
667
|
] }) }),
|
|
667
668
|
children
|
|
668
|
-
] })
|
|
669
|
+
] }) })
|
|
669
670
|
}
|
|
670
671
|
)
|
|
671
672
|
}
|
|
@@ -682,8 +683,8 @@ var CivicAuthProvider = (_a) => {
|
|
|
682
683
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactquery.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
683
684
|
AuthProvider,
|
|
684
685
|
_chunkCRTRMMJ7js.__spreadProps.call(void 0, _chunkCRTRMMJ7js.__spreadValues.call(void 0, {}, props), {
|
|
685
|
-
pkceConsumer: new (0,
|
|
686
|
-
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, UserProvider, { storage: new (0,
|
|
686
|
+
pkceConsumer: new (0, _chunkRF23Q4V6js.BrowserPublicClientPKCEProducer)(),
|
|
687
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, UserProvider, { storage: new (0, _chunkRF23Q4V6js.LocalStorageAdapter)(), children })
|
|
687
688
|
})
|
|
688
689
|
) });
|
|
689
690
|
};
|
|
@@ -693,6 +694,68 @@ var CivicAuthProvider = (_a) => {
|
|
|
693
694
|
|
|
694
695
|
|
|
695
696
|
|
|
697
|
+
// src/react/hooks/useTokenCookie.ts
|
|
698
|
+
|
|
699
|
+
var _navigationjs = require('next/navigation.js');
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
// src/lib/cookies.ts
|
|
703
|
+
var getWindowCookieValue = ({
|
|
704
|
+
key,
|
|
705
|
+
window: window2,
|
|
706
|
+
parseJson = false
|
|
707
|
+
}) => {
|
|
708
|
+
const cookie = window2.document.cookie;
|
|
709
|
+
if (!cookie) return null;
|
|
710
|
+
const cookies = cookie.split(";");
|
|
711
|
+
for (const c of cookies) {
|
|
712
|
+
const [name, value] = c.trim().split("=");
|
|
713
|
+
if (value && name === key) {
|
|
714
|
+
try {
|
|
715
|
+
const decodeURIComponentValue = decodeURIComponent(value);
|
|
716
|
+
return parseJson === true ? JSON.parse(decodeURIComponentValue) : decodeURIComponentValue;
|
|
717
|
+
} catch (e) {
|
|
718
|
+
return value;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
return null;
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
// src/react/hooks/useTokenCookie.ts
|
|
726
|
+
var getTokenFromCookie = (tokenName) => {
|
|
727
|
+
return getWindowCookieValue({
|
|
728
|
+
key: tokenName,
|
|
729
|
+
window: globalThis.window,
|
|
730
|
+
parseJson: false
|
|
731
|
+
});
|
|
732
|
+
};
|
|
733
|
+
var useTokenCookie = (tokenName) => {
|
|
734
|
+
const hasRunRef = _react.useRef.call(void 0, false);
|
|
735
|
+
const router = _navigationjs.useRouter.call(void 0, );
|
|
736
|
+
const { data: token } = _reactquery.useQuery.call(void 0, {
|
|
737
|
+
queryKey: ["token", tokenName],
|
|
738
|
+
queryFn: () => getTokenFromCookie(tokenName) || null,
|
|
739
|
+
refetchInterval: 2e3,
|
|
740
|
+
refetchIntervalInBackground: true,
|
|
741
|
+
enabled: !hasRunRef.current,
|
|
742
|
+
refetchOnWindowFocus: true
|
|
743
|
+
});
|
|
744
|
+
_react.useEffect.call(void 0, () => {
|
|
745
|
+
if (token) {
|
|
746
|
+
if (!hasRunRef.current) {
|
|
747
|
+
hasRunRef.current = true;
|
|
748
|
+
router.refresh();
|
|
749
|
+
}
|
|
750
|
+
} else {
|
|
751
|
+
hasRunRef.current = false;
|
|
752
|
+
}
|
|
753
|
+
}, [token, router]);
|
|
754
|
+
return token != null ? token : null;
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
// src/react/providers/NextAuthProvider.tsx
|
|
758
|
+
|
|
696
759
|
var queryClient2 = new (0, _reactquery.QueryClient)();
|
|
697
760
|
var CivicNextAuthProvider = (_a) => {
|
|
698
761
|
var _b = _a, {
|
|
@@ -701,18 +764,23 @@ var CivicNextAuthProvider = (_a) => {
|
|
|
701
764
|
"children"
|
|
702
765
|
]);
|
|
703
766
|
const [redirectUrl, setRedirectUrl] = _react.useState.call(void 0, "");
|
|
704
|
-
const { clientId, oauthServer, callbackUrl, challengeUrl, logoutUrl } =
|
|
767
|
+
const { clientId, oauthServer, callbackUrl, challengeUrl, logoutUrl } = _chunkSEKF2WZXjs.resolveAuthConfig.call(void 0, );
|
|
705
768
|
_react.useEffect.call(void 0, () => {
|
|
706
769
|
if (typeof globalThis.window !== "undefined") {
|
|
707
770
|
const currentUrl = globalThis.window.location.href;
|
|
708
|
-
setRedirectUrl(
|
|
771
|
+
setRedirectUrl(_chunkSEKF2WZXjs.resolveCallbackUrl.call(void 0, _chunkSEKF2WZXjs.resolveAuthConfig.call(void 0, ), currentUrl));
|
|
709
772
|
}
|
|
710
773
|
}, [callbackUrl]);
|
|
711
774
|
const user = useUserCookie();
|
|
775
|
+
const idToken = useTokenCookie("id_token" /* ID_TOKEN */);
|
|
776
|
+
const combinedUser = user ? _chunkCRTRMMJ7js.__spreadProps.call(void 0, _chunkCRTRMMJ7js.__spreadValues.call(void 0, {}, user || {}), { idToken }) : null;
|
|
777
|
+
const sessionData = _chunkCRTRMMJ7js.__spreadValues.call(void 0, {
|
|
778
|
+
authenticated: !!user
|
|
779
|
+
}, idToken ? { idToken } : {});
|
|
712
780
|
const signOut = () => _chunkCRTRMMJ7js.__async.call(void 0, void 0, null, function* () {
|
|
713
781
|
var _a2;
|
|
714
|
-
yield fetch(logoutUrl);
|
|
715
782
|
(_a2 = props.onSignOut) == null ? void 0 : _a2.call(props);
|
|
783
|
+
window.location.href = logoutUrl;
|
|
716
784
|
return;
|
|
717
785
|
});
|
|
718
786
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactquery.QueryClientProvider, { client: queryClient2, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
@@ -721,12 +789,13 @@ var CivicNextAuthProvider = (_a) => {
|
|
|
721
789
|
redirectUrl,
|
|
722
790
|
config: { oauthServer },
|
|
723
791
|
clientId,
|
|
724
|
-
pkceConsumer: new (0,
|
|
792
|
+
pkceConsumer: new (0, _chunkRF23Q4V6js.ConfidentialClientPKCEConsumer)(challengeUrl),
|
|
793
|
+
sessionData,
|
|
725
794
|
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
726
795
|
UserProvider,
|
|
727
796
|
{
|
|
728
|
-
storage: new (0,
|
|
729
|
-
user,
|
|
797
|
+
storage: new (0, _chunkSEKF2WZXjs.NextjsClientStorage)(),
|
|
798
|
+
user: combinedUser,
|
|
730
799
|
signOut,
|
|
731
800
|
children
|
|
732
801
|
}
|
|
@@ -746,31 +815,14 @@ var useUser = () => {
|
|
|
746
815
|
|
|
747
816
|
// src/react/hooks/useUserCookie.ts
|
|
748
817
|
|
|
749
|
-
var _navigationjs = require('next/navigation.js');
|
|
750
818
|
|
|
751
819
|
|
|
752
|
-
// src/lib/cookies.ts
|
|
753
|
-
var getCookieValue = (key, window2) => {
|
|
754
|
-
const cookie = window2.document.cookie;
|
|
755
|
-
if (!cookie) return null;
|
|
756
|
-
const cookies = cookie.split(";");
|
|
757
|
-
for (const c of cookies) {
|
|
758
|
-
const [name, value] = c.trim().split("=");
|
|
759
|
-
if (value && name === key) {
|
|
760
|
-
try {
|
|
761
|
-
return JSON.parse(decodeURIComponent(value));
|
|
762
|
-
} catch (e) {
|
|
763
|
-
console.log("Error parsing cookie value", e);
|
|
764
|
-
return value;
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
return null;
|
|
769
|
-
};
|
|
770
|
-
|
|
771
|
-
// src/react/hooks/useUserCookie.ts
|
|
772
820
|
var getUserFromCookie = () => {
|
|
773
|
-
const userCookie =
|
|
821
|
+
const userCookie = getWindowCookieValue({
|
|
822
|
+
key: "user" /* USER */,
|
|
823
|
+
window: globalThis.window,
|
|
824
|
+
parseJson: true
|
|
825
|
+
});
|
|
774
826
|
return userCookie;
|
|
775
827
|
};
|
|
776
828
|
var useUserCookie = () => {
|
|
@@ -794,7 +846,7 @@ var useUserCookie = () => {
|
|
|
794
846
|
hasRunRef.current = false;
|
|
795
847
|
}
|
|
796
848
|
}, [user, router]);
|
|
797
|
-
return user;
|
|
849
|
+
return user != null ? user : null;
|
|
798
850
|
};
|
|
799
851
|
|
|
800
852
|
// src/react/hooks/useConfig.tsx
|
|
@@ -807,6 +859,16 @@ var useConfig = () => {
|
|
|
807
859
|
return context;
|
|
808
860
|
};
|
|
809
861
|
|
|
862
|
+
// src/react/hooks/useIframe.tsx
|
|
863
|
+
|
|
864
|
+
var useIframe = () => {
|
|
865
|
+
const context = _react.useContext.call(void 0, IframeContext);
|
|
866
|
+
if (!context) {
|
|
867
|
+
throw new Error("useIframe must be used within an IframeProvider");
|
|
868
|
+
}
|
|
869
|
+
return context;
|
|
870
|
+
};
|
|
871
|
+
|
|
810
872
|
// src/react/components/UserButton.tsx
|
|
811
873
|
|
|
812
874
|
|
|
@@ -882,7 +944,7 @@ var UserButton = ({
|
|
|
882
944
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
883
945
|
"button",
|
|
884
946
|
{
|
|
885
|
-
className:
|
|
947
|
+
className: _chunkRF23Q4V6js.cn.call(void 0,
|
|
886
948
|
"cac-flex cac-w-full cac-items-center cac-justify-between cac-gap-2 cac-rounded-full cac-border cac-border-neutral-500 cac-px-3 cac-py-2 cac-text-neutral-500 cac-transition-colors hover:cac-bg-neutral-200 hover:cac-bg-opacity-50",
|
|
887
949
|
className
|
|
888
950
|
),
|
|
@@ -921,7 +983,7 @@ var UserButton = ({
|
|
|
921
983
|
"button",
|
|
922
984
|
{
|
|
923
985
|
"data-testid": "sign-in-button",
|
|
924
|
-
className:
|
|
986
|
+
className: _chunkRF23Q4V6js.cn.call(void 0,
|
|
925
987
|
"cac-rounded-full cac-border cac-border-neutral-500 cac-px-3 cac-py-2 cac-transition-colors hover:cac-bg-neutral-200 hover:cac-bg-opacity-50",
|
|
926
988
|
className
|
|
927
989
|
),
|
|
@@ -942,7 +1004,7 @@ var SignInButton = ({
|
|
|
942
1004
|
"button",
|
|
943
1005
|
{
|
|
944
1006
|
"data-testid": "sign-in-button",
|
|
945
|
-
className:
|
|
1007
|
+
className: _chunkRF23Q4V6js.cn.call(void 0,
|
|
946
1008
|
"cac-rounded-full cac-border cac-border-neutral-500 cac-px-3 cac-py-2 cac-transition-colors hover:cac-bg-neutral-200 hover:cac-bg-opacity-50",
|
|
947
1009
|
className
|
|
948
1010
|
),
|
|
@@ -959,7 +1021,7 @@ var SignOutButton = ({ className }) => {
|
|
|
959
1021
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
960
1022
|
"button",
|
|
961
1023
|
{
|
|
962
|
-
className:
|
|
1024
|
+
className: _chunkRF23Q4V6js.cn.call(void 0,
|
|
963
1025
|
"cac-rounded-full cac-border cac-border-neutral-500 cac-px-3 cac-py-2 cac-transition-colors hover:cac-bg-neutral-200 hover:cac-bg-opacity-50",
|
|
964
1026
|
className
|
|
965
1027
|
),
|
|
@@ -972,7 +1034,7 @@ var SignOutButton = ({ className }) => {
|
|
|
972
1034
|
// src/react/components/NextLogOut.tsx
|
|
973
1035
|
|
|
974
1036
|
var NextLogOut = ({ children }) => {
|
|
975
|
-
const config =
|
|
1037
|
+
const config = _chunkSEKF2WZXjs.resolveAuthConfig.call(void 0, );
|
|
976
1038
|
const logoutUrl = `${config.logoutUrl}`;
|
|
977
1039
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "a", { href: logoutUrl, children });
|
|
978
1040
|
};
|
|
@@ -990,5 +1052,7 @@ var NextLogOut = ({ children }) => {
|
|
|
990
1052
|
|
|
991
1053
|
|
|
992
1054
|
|
|
993
|
-
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
exports.CivicAuthIframeContainer = CivicAuthIframeContainer; exports.CivicAuthProvider = CivicAuthProvider; exports.CivicNextAuthProvider = CivicNextAuthProvider; exports.NextLogOut = NextLogOut; exports.SignInButton = SignInButton; exports.SignOutButton = SignOutButton; exports.UserButton = UserButton; exports.useAuth = useAuth; exports.useConfig = useConfig; exports.useIframe = useIframe; exports.useSession = useSession; exports.useToken = useToken; exports.useTokenCookie = useTokenCookie; exports.useUser = useUser; exports.useUserCookie = useUserCookie;
|
|
994
1058
|
//# sourceMappingURL=react.js.map
|