@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.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
NextjsClientStorage,
|
|
3
3
|
resolveAuthConfig,
|
|
4
4
|
resolveCallbackUrl
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-5XL2ST72.mjs";
|
|
6
6
|
import {
|
|
7
7
|
BrowserAuthenticationInitiator,
|
|
8
8
|
BrowserAuthenticationService,
|
|
@@ -12,12 +12,13 @@ import {
|
|
|
12
12
|
GenericUserSession,
|
|
13
13
|
IFRAME_ID,
|
|
14
14
|
LocalStorageAdapter,
|
|
15
|
+
TOKEN_EXCHANGE_TRIGGER_TEXT,
|
|
15
16
|
cn,
|
|
16
17
|
convertForwardedTokenFormat,
|
|
17
18
|
generateState,
|
|
18
19
|
getUser,
|
|
19
20
|
isWindowInIframe
|
|
20
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-G3P5TIO2.mjs";
|
|
21
22
|
import {
|
|
22
23
|
__async,
|
|
23
24
|
__objRest,
|
|
@@ -59,32 +60,16 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
|
59
60
|
import { useContext as useContext2 } from "react";
|
|
60
61
|
|
|
61
62
|
// src/react/providers/SessionProvider.tsx
|
|
62
|
-
import {
|
|
63
|
-
createContext as createContext2
|
|
64
|
-
} from "react";
|
|
63
|
+
import { createContext as createContext2 } from "react";
|
|
65
64
|
import { jsx } from "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 = createContext2(defaultSession);
|
|
76
|
-
var SessionProvider = ({
|
|
77
|
-
children,
|
|
78
|
-
session,
|
|
79
|
-
iframeRef,
|
|
80
|
-
setAuthResponseUrl
|
|
81
|
-
}) => /* @__PURE__ */ jsx(
|
|
82
|
-
SessionContext.Provider,
|
|
83
|
-
{
|
|
84
|
-
value: __spreadProps(__spreadValues({}, session || defaultSession), { iframeRef, setAuthResponseUrl }),
|
|
85
|
-
children
|
|
86
|
-
}
|
|
87
|
-
);
|
|
72
|
+
var SessionProvider = ({ children, session }) => /* @__PURE__ */ jsx(SessionContext.Provider, { value: __spreadValues(__spreadValues({}, defaultSession), session || {}), children });
|
|
88
73
|
|
|
89
74
|
// src/react/hooks/useSession.tsx
|
|
90
75
|
var useSession = () => {
|
|
@@ -274,7 +259,7 @@ var CivicAuthIframe = forwardRef(
|
|
|
274
259
|
{
|
|
275
260
|
id: 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
|
);
|
|
@@ -283,11 +268,11 @@ var CivicAuthIframe = forwardRef(
|
|
|
283
268
|
CivicAuthIframe.displayName = "CivicAuthIframe";
|
|
284
269
|
|
|
285
270
|
// src/react/components/CivicAuthIframeContainer.tsx
|
|
286
|
-
import {
|
|
271
|
+
import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
287
272
|
function NoChrome({
|
|
288
273
|
children
|
|
289
274
|
}) {
|
|
290
|
-
return /* @__PURE__ */ jsx7(
|
|
275
|
+
return /* @__PURE__ */ jsx7("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] = useState(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 = useCallback(() => {
|
|
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(TOKEN_EXCHANGE_TRIGGER_TEXT)) {
|
|
339
324
|
console.log(
|
|
340
|
-
|
|
325
|
+
`${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__ */ jsxs3(WrapperComponent, { onClose, children: [
|
|
385
|
-
showLoadingIcon && /* @__PURE__ */ jsx7("div", { className: "cac-absolute cac-inset-0 cac-flex cac-items-center cac-justify-center cac-rounded-3xl cac-bg-
|
|
370
|
+
showLoadingIcon && /* @__PURE__ */ jsx7("div", { className: "cac-absolute cac-inset-0 cac-flex cac-items-center cac-justify-center cac-rounded-3xl cac-bg-white", children: /* @__PURE__ */ jsx7(LoadingIcon, {}) }),
|
|
386
371
|
/* @__PURE__ */ jsx7(CivicAuthIframe, { ref: iframeRef, onLoad: handleIframeLoad })
|
|
387
372
|
] });
|
|
388
373
|
};
|
|
@@ -422,8 +407,25 @@ var ConfigProvider = ({
|
|
|
422
407
|
}
|
|
423
408
|
);
|
|
424
409
|
|
|
410
|
+
// src/react/providers/IframeProvider.tsx
|
|
411
|
+
import {
|
|
412
|
+
createContext as createContext6
|
|
413
|
+
} from "react";
|
|
414
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
415
|
+
var defaultIframe = {
|
|
416
|
+
iframeRef: null,
|
|
417
|
+
setAuthResponseUrl: () => {
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
var IframeContext = createContext6(defaultIframe);
|
|
421
|
+
var IframeProvider = ({
|
|
422
|
+
children,
|
|
423
|
+
iframeRef,
|
|
424
|
+
setAuthResponseUrl
|
|
425
|
+
}) => /* @__PURE__ */ jsx9(IframeContext.Provider, { value: { iframeRef, setAuthResponseUrl }, children });
|
|
426
|
+
|
|
425
427
|
// src/shared/AuthProvider.tsx
|
|
426
|
-
import { jsx as
|
|
428
|
+
import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
427
429
|
var globalThisObject;
|
|
428
430
|
if (typeof window !== "undefined") {
|
|
429
431
|
globalThisObject = window;
|
|
@@ -434,7 +436,7 @@ if (typeof window !== "undefined") {
|
|
|
434
436
|
}
|
|
435
437
|
globalThisObject.globalThis = globalThisObject;
|
|
436
438
|
function BlockDisplay({ children }) {
|
|
437
|
-
return /* @__PURE__ */
|
|
439
|
+
return /* @__PURE__ */ jsx10("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__ */ jsx10("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] = useState2(null);
|
|
451
454
|
const [currentUrl, setCurrentUrl] = useState2(null);
|
|
@@ -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) {
|
|
@@ -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
|
});
|
|
@@ -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
|
-
} = useQuery2({
|
|
616
|
+
useQuery2({
|
|
615
617
|
queryKey: ["autoSignIn", modalIframe, redirectUrl, isAuthenticated],
|
|
616
618
|
queryFn: () => __async(void 0, null, function* () {
|
|
617
619
|
if (!modalIframe && redirectUrl && !isAuthenticated && iframeRef.current) {
|
|
@@ -633,25 +635,24 @@ var AuthProvider = ({
|
|
|
633
635
|
}),
|
|
634
636
|
[isLoading, error, signOutMutation, isAuthenticated, signIn]
|
|
635
637
|
);
|
|
636
|
-
return /* @__PURE__ */
|
|
638
|
+
return /* @__PURE__ */ jsx10(AuthContext.Provider, { value, children: /* @__PURE__ */ jsx10(
|
|
637
639
|
ConfigProvider,
|
|
638
640
|
{
|
|
639
641
|
config,
|
|
640
642
|
redirectUrl,
|
|
641
643
|
modalIframe,
|
|
642
644
|
serverTokenExchange,
|
|
643
|
-
children: /* @__PURE__ */
|
|
644
|
-
|
|
645
|
+
children: /* @__PURE__ */ jsx10(
|
|
646
|
+
IframeProvider,
|
|
645
647
|
{
|
|
646
|
-
session,
|
|
647
648
|
setAuthResponseUrl,
|
|
648
649
|
iframeRef,
|
|
649
|
-
children: /* @__PURE__ */ jsxs4(TokenProvider, { children: [
|
|
650
|
-
modalIframe && !isInIframe && !(session == null ? void 0 : session.authenticated) && /* @__PURE__ */
|
|
650
|
+
children: /* @__PURE__ */ jsx10(SessionProvider, { session, children: /* @__PURE__ */ jsxs4(TokenProvider, { children: [
|
|
651
|
+
modalIframe && !isInIframe && !(session == null ? void 0 : session.authenticated) && /* @__PURE__ */ jsx10(
|
|
651
652
|
"div",
|
|
652
653
|
{
|
|
653
654
|
style: showIFrame ? { display: "block" } : { display: "none" },
|
|
654
|
-
children: /* @__PURE__ */
|
|
655
|
+
children: /* @__PURE__ */ jsx10(
|
|
655
656
|
CivicAuthIframeContainer,
|
|
656
657
|
{
|
|
657
658
|
onClose: () => setShowIFrame(false)
|
|
@@ -659,13 +660,13 @@ var AuthProvider = ({
|
|
|
659
660
|
)
|
|
660
661
|
}
|
|
661
662
|
),
|
|
662
|
-
modalIframe && (isInIframe || isRedirecting || isLoading) && /* @__PURE__ */
|
|
663
|
-
(tokenExchangeError || error) && /* @__PURE__ */
|
|
663
|
+
modalIframe && (isInIframe || isRedirecting || isLoading && !serverTokenExchange) && /* @__PURE__ */ jsx10(BlockDisplay, { children: /* @__PURE__ */ jsx10(LoadingIcon, {}) }),
|
|
664
|
+
(tokenExchangeError || error) && /* @__PURE__ */ jsx10(BlockDisplay, { children: /* @__PURE__ */ jsxs4("div", { children: [
|
|
664
665
|
"Error: ",
|
|
665
666
|
(tokenExchangeError || error).message
|
|
666
667
|
] }) }),
|
|
667
668
|
children
|
|
668
|
-
] })
|
|
669
|
+
] }) })
|
|
669
670
|
}
|
|
670
671
|
)
|
|
671
672
|
}
|
|
@@ -675,24 +676,86 @@ var AuthProvider = ({
|
|
|
675
676
|
// src/shared/CivicAuthProvider.tsx
|
|
676
677
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
677
678
|
import "@civic/auth/styles.css";
|
|
678
|
-
import { jsx as
|
|
679
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
679
680
|
var queryClient = new QueryClient();
|
|
680
681
|
var CivicAuthProvider = (_a) => {
|
|
681
682
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
682
|
-
return /* @__PURE__ */
|
|
683
|
+
return /* @__PURE__ */ jsx11(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx11(
|
|
683
684
|
AuthProvider,
|
|
684
685
|
__spreadProps(__spreadValues({}, props), {
|
|
685
686
|
pkceConsumer: new BrowserPublicClientPKCEProducer(),
|
|
686
|
-
children: /* @__PURE__ */
|
|
687
|
+
children: /* @__PURE__ */ jsx11(UserProvider, { storage: new LocalStorageAdapter(), children })
|
|
687
688
|
})
|
|
688
689
|
) });
|
|
689
690
|
};
|
|
690
691
|
|
|
691
692
|
// src/react/providers/NextAuthProvider.tsx
|
|
692
|
-
import { useEffect as
|
|
693
|
+
import { useEffect as useEffect4, useState as useState3 } from "react";
|
|
693
694
|
import { QueryClient as QueryClient2, QueryClientProvider as QueryClientProvider2 } from "@tanstack/react-query";
|
|
694
695
|
import "@civic/auth/styles.css";
|
|
695
|
-
|
|
696
|
+
|
|
697
|
+
// src/react/hooks/useTokenCookie.ts
|
|
698
|
+
import { useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
699
|
+
import { useRouter } from "next/navigation.js";
|
|
700
|
+
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
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 = useRef3(false);
|
|
735
|
+
const router = useRouter();
|
|
736
|
+
const { data: token } = useQuery3({
|
|
737
|
+
queryKey: ["token", tokenName],
|
|
738
|
+
queryFn: () => getTokenFromCookie(tokenName) || null,
|
|
739
|
+
refetchInterval: 2e3,
|
|
740
|
+
refetchIntervalInBackground: true,
|
|
741
|
+
enabled: !hasRunRef.current,
|
|
742
|
+
refetchOnWindowFocus: true
|
|
743
|
+
});
|
|
744
|
+
useEffect3(() => {
|
|
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
|
+
import { jsx as jsx12 } from "react/jsx-runtime";
|
|
696
759
|
var queryClient2 = new QueryClient2();
|
|
697
760
|
var CivicNextAuthProvider = (_a) => {
|
|
698
761
|
var _b = _a, {
|
|
@@ -702,31 +765,37 @@ var CivicNextAuthProvider = (_a) => {
|
|
|
702
765
|
]);
|
|
703
766
|
const [redirectUrl, setRedirectUrl] = useState3("");
|
|
704
767
|
const { clientId, oauthServer, callbackUrl, challengeUrl, logoutUrl } = resolveAuthConfig();
|
|
705
|
-
|
|
768
|
+
useEffect4(() => {
|
|
706
769
|
if (typeof globalThis.window !== "undefined") {
|
|
707
770
|
const currentUrl = globalThis.window.location.href;
|
|
708
771
|
setRedirectUrl(resolveCallbackUrl(resolveAuthConfig(), currentUrl));
|
|
709
772
|
}
|
|
710
773
|
}, [callbackUrl]);
|
|
711
774
|
const user = useUserCookie();
|
|
775
|
+
const idToken = useTokenCookie("id_token" /* ID_TOKEN */);
|
|
776
|
+
const combinedUser = user ? __spreadProps(__spreadValues({}, user || {}), { idToken }) : null;
|
|
777
|
+
const sessionData = __spreadValues({
|
|
778
|
+
authenticated: !!user
|
|
779
|
+
}, idToken ? { idToken } : {});
|
|
712
780
|
const signOut = () => __async(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
|
-
return /* @__PURE__ */
|
|
786
|
+
return /* @__PURE__ */ jsx12(QueryClientProvider2, { client: queryClient2, children: /* @__PURE__ */ jsx12(
|
|
719
787
|
AuthProvider,
|
|
720
788
|
__spreadProps(__spreadValues({}, props), {
|
|
721
789
|
redirectUrl,
|
|
722
790
|
config: { oauthServer },
|
|
723
791
|
clientId,
|
|
724
792
|
pkceConsumer: new ConfidentialClientPKCEConsumer(challengeUrl),
|
|
725
|
-
|
|
793
|
+
sessionData,
|
|
794
|
+
children: /* @__PURE__ */ jsx12(
|
|
726
795
|
UserProvider,
|
|
727
796
|
{
|
|
728
797
|
storage: new NextjsClientStorage(),
|
|
729
|
-
user,
|
|
798
|
+
user: combinedUser,
|
|
730
799
|
signOut,
|
|
731
800
|
children
|
|
732
801
|
}
|
|
@@ -745,38 +814,21 @@ var useUser = () => {
|
|
|
745
814
|
};
|
|
746
815
|
|
|
747
816
|
// src/react/hooks/useUserCookie.ts
|
|
748
|
-
import { useEffect as
|
|
749
|
-
import { useRouter } from "next/navigation.js";
|
|
750
|
-
import { useQuery as
|
|
751
|
-
|
|
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
|
|
817
|
+
import { useEffect as useEffect5, useRef as useRef4 } from "react";
|
|
818
|
+
import { useRouter as useRouter2 } from "next/navigation.js";
|
|
819
|
+
import { useQuery as useQuery4 } from "@tanstack/react-query";
|
|
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 = () => {
|
|
777
|
-
const hasRunRef =
|
|
778
|
-
const router =
|
|
779
|
-
const { data: user } =
|
|
829
|
+
const hasRunRef = useRef4(false);
|
|
830
|
+
const router = useRouter2();
|
|
831
|
+
const { data: user } = useQuery4({
|
|
780
832
|
queryKey: ["user"],
|
|
781
833
|
queryFn: () => getUserFromCookie(),
|
|
782
834
|
refetchInterval: 2e3,
|
|
@@ -784,7 +836,7 @@ var useUserCookie = () => {
|
|
|
784
836
|
enabled: !hasRunRef.current,
|
|
785
837
|
refetchOnWindowFocus: true
|
|
786
838
|
});
|
|
787
|
-
|
|
839
|
+
useEffect5(() => {
|
|
788
840
|
if (user) {
|
|
789
841
|
if (!hasRunRef.current) {
|
|
790
842
|
hasRunRef.current = true;
|
|
@@ -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,10 +859,20 @@ var useConfig = () => {
|
|
|
807
859
|
return context;
|
|
808
860
|
};
|
|
809
861
|
|
|
862
|
+
// src/react/hooks/useIframe.tsx
|
|
863
|
+
import { useContext as useContext6 } from "react";
|
|
864
|
+
var useIframe = () => {
|
|
865
|
+
const context = useContext6(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
|
-
import { useCallback as useCallback3, useEffect as
|
|
812
|
-
import { jsx as
|
|
813
|
-
var ChevronDown = () => /* @__PURE__ */
|
|
873
|
+
import { useCallback as useCallback3, useEffect as useEffect6, useState as useState4 } from "react";
|
|
874
|
+
import { jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
875
|
+
var ChevronDown = () => /* @__PURE__ */ jsx13(
|
|
814
876
|
"svg",
|
|
815
877
|
{
|
|
816
878
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -823,10 +885,10 @@ var ChevronDown = () => /* @__PURE__ */ jsx12(
|
|
|
823
885
|
strokeLinecap: "round",
|
|
824
886
|
strokeLinejoin: "round",
|
|
825
887
|
className: "lucide lucide-chevron-down",
|
|
826
|
-
children: /* @__PURE__ */
|
|
888
|
+
children: /* @__PURE__ */ jsx13("path", { d: "m6 9 6 6 6-6" })
|
|
827
889
|
}
|
|
828
890
|
);
|
|
829
|
-
var ChevronUp = () => /* @__PURE__ */
|
|
891
|
+
var ChevronUp = () => /* @__PURE__ */ jsx13(
|
|
830
892
|
"svg",
|
|
831
893
|
{
|
|
832
894
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -839,7 +901,7 @@ var ChevronUp = () => /* @__PURE__ */ jsx12(
|
|
|
839
901
|
strokeLinecap: "round",
|
|
840
902
|
strokeLinejoin: "round",
|
|
841
903
|
className: "lucide lucide-chevron-up",
|
|
842
|
-
children: /* @__PURE__ */
|
|
904
|
+
children: /* @__PURE__ */ jsx13("path", { d: "m18 15-6-6-6 6" })
|
|
843
905
|
}
|
|
844
906
|
);
|
|
845
907
|
var UserButton = ({
|
|
@@ -867,7 +929,7 @@ var UserButton = ({
|
|
|
867
929
|
setIsOpen(false);
|
|
868
930
|
}
|
|
869
931
|
}, []);
|
|
870
|
-
|
|
932
|
+
useEffect6(() => {
|
|
871
933
|
if (isOpen) {
|
|
872
934
|
window.addEventListener("click", handleClickOutside);
|
|
873
935
|
window.addEventListener("keydown", handleEscape);
|
|
@@ -888,24 +950,24 @@ var UserButton = ({
|
|
|
888
950
|
),
|
|
889
951
|
onClick: () => setIsOpen((isOpen2) => !isOpen2),
|
|
890
952
|
children: [
|
|
891
|
-
(user == null ? void 0 : user.picture) ? /* @__PURE__ */
|
|
953
|
+
(user == null ? void 0 : user.picture) ? /* @__PURE__ */ jsx13("span", { className: "cac-relative cac-flex cac-h-10 cac-w-10 cac-shrink-0 cac-gap-2 cac-overflow-hidden cac-rounded-full", children: /* @__PURE__ */ jsx13(
|
|
892
954
|
"img",
|
|
893
955
|
{
|
|
894
956
|
className: "cac-h-full cac-w-full cac-object-cover",
|
|
895
957
|
src: user.picture,
|
|
896
958
|
alt: (user == null ? void 0 : user.name) || (user == null ? void 0 : user.email)
|
|
897
959
|
}
|
|
898
|
-
) }) : /* @__PURE__ */
|
|
899
|
-
/* @__PURE__ */
|
|
900
|
-
isOpen ? /* @__PURE__ */
|
|
960
|
+
) }) : /* @__PURE__ */ jsx13("div", {}),
|
|
961
|
+
/* @__PURE__ */ jsx13("span", { children: (user == null ? void 0 : user.name) || (user == null ? void 0 : user.email) }),
|
|
962
|
+
isOpen ? /* @__PURE__ */ jsx13(ChevronUp, {}) : /* @__PURE__ */ jsx13(ChevronDown, {})
|
|
901
963
|
]
|
|
902
964
|
}
|
|
903
965
|
),
|
|
904
|
-
/* @__PURE__ */
|
|
966
|
+
/* @__PURE__ */ jsx13(
|
|
905
967
|
"div",
|
|
906
968
|
{
|
|
907
969
|
className: isOpen ? "cac-absolute cac-right-0 cac-mt-2 cac-w-full cac-rounded-lg cac-bg-white cac-py-2 cac-text-neutral-500 cac-shadow-xl" : "cac-hidden",
|
|
908
|
-
children: /* @__PURE__ */
|
|
970
|
+
children: /* @__PURE__ */ jsx13("ul", { children: /* @__PURE__ */ jsx13("li", { children: /* @__PURE__ */ jsx13(
|
|
909
971
|
"button",
|
|
910
972
|
{
|
|
911
973
|
className: "cac-block cac-w-full cac-px-4 cac-py-2 cac-transition-colors hover:cac-bg-neutral-200 hover:cac-bg-opacity-50",
|
|
@@ -917,7 +979,7 @@ var UserButton = ({
|
|
|
917
979
|
)
|
|
918
980
|
] });
|
|
919
981
|
}
|
|
920
|
-
return /* @__PURE__ */
|
|
982
|
+
return /* @__PURE__ */ jsx13(
|
|
921
983
|
"button",
|
|
922
984
|
{
|
|
923
985
|
"data-testid": "sign-in-button",
|
|
@@ -932,13 +994,13 @@ var UserButton = ({
|
|
|
932
994
|
};
|
|
933
995
|
|
|
934
996
|
// src/react/components/SignInButton.tsx
|
|
935
|
-
import { jsx as
|
|
997
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
936
998
|
var SignInButton = ({
|
|
937
999
|
displayMode,
|
|
938
1000
|
className
|
|
939
1001
|
}) => {
|
|
940
1002
|
const { signIn } = useUser();
|
|
941
|
-
return /* @__PURE__ */
|
|
1003
|
+
return /* @__PURE__ */ jsx14(
|
|
942
1004
|
"button",
|
|
943
1005
|
{
|
|
944
1006
|
"data-testid": "sign-in-button",
|
|
@@ -953,10 +1015,10 @@ var SignInButton = ({
|
|
|
953
1015
|
};
|
|
954
1016
|
|
|
955
1017
|
// src/react/components/SignOutButton.tsx
|
|
956
|
-
import { jsx as
|
|
1018
|
+
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
957
1019
|
var SignOutButton = ({ className }) => {
|
|
958
1020
|
const { signOut } = useUser();
|
|
959
|
-
return /* @__PURE__ */
|
|
1021
|
+
return /* @__PURE__ */ jsx15(
|
|
960
1022
|
"button",
|
|
961
1023
|
{
|
|
962
1024
|
className: cn(
|
|
@@ -970,11 +1032,11 @@ var SignOutButton = ({ className }) => {
|
|
|
970
1032
|
};
|
|
971
1033
|
|
|
972
1034
|
// src/react/components/NextLogOut.tsx
|
|
973
|
-
import { jsx as
|
|
1035
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
974
1036
|
var NextLogOut = ({ children }) => {
|
|
975
1037
|
const config = resolveAuthConfig();
|
|
976
1038
|
const logoutUrl = `${config.logoutUrl}`;
|
|
977
|
-
return /* @__PURE__ */
|
|
1039
|
+
return /* @__PURE__ */ jsx16("a", { href: logoutUrl, children });
|
|
978
1040
|
};
|
|
979
1041
|
export {
|
|
980
1042
|
CivicAuthIframeContainer,
|
|
@@ -986,8 +1048,10 @@ export {
|
|
|
986
1048
|
UserButton,
|
|
987
1049
|
useAuth,
|
|
988
1050
|
useConfig,
|
|
1051
|
+
useIframe,
|
|
989
1052
|
useSession,
|
|
990
1053
|
useToken,
|
|
1054
|
+
useTokenCookie,
|
|
991
1055
|
useUser,
|
|
992
1056
|
useUserCookie
|
|
993
1057
|
};
|