@civic/auth 0.0.1-beta.16 → 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-FBU2CKWK.mjs → chunk-5XL2ST72.mjs} +45 -14
- package/dist/chunk-5XL2ST72.mjs.map +1 -0
- package/dist/chunk-CRTRMMJ7.js.map +1 -1
- package/dist/{chunk-RKQDQJOM.mjs → chunk-G3P5TIO2.mjs} +1 -1
- package/dist/chunk-G3P5TIO2.mjs.map +1 -0
- package/dist/{chunk-CHY6AHA7.js → chunk-RF23Q4V6.js} +1 -1
- package/dist/chunk-RF23Q4V6.js.map +1 -0
- package/dist/{chunk-N4SAZYOX.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.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js.map +1 -1
- package/dist/nextjs.d.mts +3 -9
- package/dist/nextjs.d.ts +3 -9
- package/dist/nextjs.js +24 -24
- package/dist/nextjs.js.map +1 -1
- package/dist/nextjs.mjs +3 -3
- 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 +152 -89
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +167 -104
- 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.js.map +1 -1
- 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 +1 -1
- package/dist/chunk-CHY6AHA7.js.map +0 -1
- package/dist/chunk-FBU2CKWK.mjs.map +0 -1
- package/dist/chunk-N4SAZYOX.js.map +0 -1
- package/dist/chunk-RKQDQJOM.mjs.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,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
generateState,
|
|
19
19
|
getUser,
|
|
20
20
|
isWindowInIframe
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-G3P5TIO2.mjs";
|
|
22
22
|
import {
|
|
23
23
|
__async,
|
|
24
24
|
__objRest,
|
|
@@ -60,32 +60,16 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
|
60
60
|
import { useContext as useContext2 } from "react";
|
|
61
61
|
|
|
62
62
|
// src/react/providers/SessionProvider.tsx
|
|
63
|
-
import {
|
|
64
|
-
createContext as createContext2
|
|
65
|
-
} from "react";
|
|
63
|
+
import { createContext as createContext2 } from "react";
|
|
66
64
|
import { jsx } from "react/jsx-runtime";
|
|
67
65
|
var defaultSession = {
|
|
68
66
|
authenticated: false,
|
|
69
67
|
idToken: void 0,
|
|
70
68
|
accessToken: void 0,
|
|
71
|
-
displayMode: "iframe"
|
|
72
|
-
iframeRef: null,
|
|
73
|
-
setAuthResponseUrl: () => {
|
|
74
|
-
}
|
|
69
|
+
displayMode: "iframe"
|
|
75
70
|
};
|
|
76
71
|
var SessionContext = createContext2(defaultSession);
|
|
77
|
-
var SessionProvider = ({
|
|
78
|
-
children,
|
|
79
|
-
session,
|
|
80
|
-
iframeRef,
|
|
81
|
-
setAuthResponseUrl
|
|
82
|
-
}) => /* @__PURE__ */ jsx(
|
|
83
|
-
SessionContext.Provider,
|
|
84
|
-
{
|
|
85
|
-
value: __spreadProps(__spreadValues({}, session || defaultSession), { iframeRef, setAuthResponseUrl }),
|
|
86
|
-
children
|
|
87
|
-
}
|
|
88
|
-
);
|
|
72
|
+
var SessionProvider = ({ children, session }) => /* @__PURE__ */ jsx(SessionContext.Provider, { value: __spreadValues(__spreadValues({}, defaultSession), session || {}), children });
|
|
89
73
|
|
|
90
74
|
// src/react/hooks/useSession.tsx
|
|
91
75
|
var useSession = () => {
|
|
@@ -328,7 +312,7 @@ var CivicAuthIframeContainer = ({
|
|
|
328
312
|
const [isLoading, setIsLoading] = useState(true);
|
|
329
313
|
const { isLoading: isAuthLoading } = useAuth();
|
|
330
314
|
const config = useConfig();
|
|
331
|
-
const { setAuthResponseUrl, iframeRef } =
|
|
315
|
+
const { setAuthResponseUrl, iframeRef } = useIframe();
|
|
332
316
|
const processIframeUrl = useCallback(() => {
|
|
333
317
|
if (iframeRef && iframeRef.current && iframeRef.current.contentWindow) {
|
|
334
318
|
try {
|
|
@@ -423,8 +407,25 @@ var ConfigProvider = ({
|
|
|
423
407
|
}
|
|
424
408
|
);
|
|
425
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
|
+
|
|
426
427
|
// src/shared/AuthProvider.tsx
|
|
427
|
-
import { jsx as
|
|
428
|
+
import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
428
429
|
var globalThisObject;
|
|
429
430
|
if (typeof window !== "undefined") {
|
|
430
431
|
globalThisObject = window;
|
|
@@ -435,7 +436,7 @@ if (typeof window !== "undefined") {
|
|
|
435
436
|
}
|
|
436
437
|
globalThisObject.globalThis = globalThisObject;
|
|
437
438
|
function BlockDisplay({ children }) {
|
|
438
|
-
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 }) });
|
|
439
440
|
}
|
|
440
441
|
var AuthProvider = ({
|
|
441
442
|
children,
|
|
@@ -446,7 +447,8 @@ var AuthProvider = ({
|
|
|
446
447
|
onSignOut,
|
|
447
448
|
pkceConsumer,
|
|
448
449
|
nonce,
|
|
449
|
-
modalIframe = true
|
|
450
|
+
modalIframe = true,
|
|
451
|
+
sessionData: inputSessionData
|
|
450
452
|
}) => {
|
|
451
453
|
const [iframeUrl, setIframeUrl] = useState2(null);
|
|
452
454
|
const [currentUrl, setCurrentUrl] = useState2(null);
|
|
@@ -499,9 +501,16 @@ var AuthProvider = ({
|
|
|
499
501
|
if (!authService) {
|
|
500
502
|
return { authenticated: false };
|
|
501
503
|
}
|
|
504
|
+
if (inputSessionData) {
|
|
505
|
+
return inputSessionData;
|
|
506
|
+
}
|
|
502
507
|
const url = new URL(
|
|
503
508
|
authResponseUrl ? authResponseUrl : globalThis.window.location.href || ""
|
|
504
509
|
);
|
|
510
|
+
const existingSessionData = yield authService.validateExistingSession();
|
|
511
|
+
if (existingSessionData.authenticated) {
|
|
512
|
+
return existingSessionData;
|
|
513
|
+
}
|
|
505
514
|
const code = url.searchParams.get("code");
|
|
506
515
|
const state = url.searchParams.get("state");
|
|
507
516
|
if (!serverTokenExchange && code && state && !isInIframe) {
|
|
@@ -529,10 +538,6 @@ var AuthProvider = ({
|
|
|
529
538
|
return { authenticated: false };
|
|
530
539
|
}
|
|
531
540
|
}
|
|
532
|
-
const existingSessionData = yield authService.validateExistingSession();
|
|
533
|
-
if (existingSessionData.authenticated) {
|
|
534
|
-
return existingSessionData;
|
|
535
|
-
}
|
|
536
541
|
return existingSessionData;
|
|
537
542
|
})
|
|
538
543
|
});
|
|
@@ -608,11 +613,7 @@ var AuthProvider = ({
|
|
|
608
613
|
() => session ? session.authenticated : false,
|
|
609
614
|
[session]
|
|
610
615
|
);
|
|
611
|
-
|
|
612
|
-
data: autoSignIn,
|
|
613
|
-
isLoading: autoSignInLoading,
|
|
614
|
-
error: autoSignInError
|
|
615
|
-
} = useQuery2({
|
|
616
|
+
useQuery2({
|
|
616
617
|
queryKey: ["autoSignIn", modalIframe, redirectUrl, isAuthenticated],
|
|
617
618
|
queryFn: () => __async(void 0, null, function* () {
|
|
618
619
|
if (!modalIframe && redirectUrl && !isAuthenticated && iframeRef.current) {
|
|
@@ -634,25 +635,24 @@ var AuthProvider = ({
|
|
|
634
635
|
}),
|
|
635
636
|
[isLoading, error, signOutMutation, isAuthenticated, signIn]
|
|
636
637
|
);
|
|
637
|
-
return /* @__PURE__ */
|
|
638
|
+
return /* @__PURE__ */ jsx10(AuthContext.Provider, { value, children: /* @__PURE__ */ jsx10(
|
|
638
639
|
ConfigProvider,
|
|
639
640
|
{
|
|
640
641
|
config,
|
|
641
642
|
redirectUrl,
|
|
642
643
|
modalIframe,
|
|
643
644
|
serverTokenExchange,
|
|
644
|
-
children: /* @__PURE__ */
|
|
645
|
-
|
|
645
|
+
children: /* @__PURE__ */ jsx10(
|
|
646
|
+
IframeProvider,
|
|
646
647
|
{
|
|
647
|
-
session,
|
|
648
648
|
setAuthResponseUrl,
|
|
649
649
|
iframeRef,
|
|
650
|
-
children: /* @__PURE__ */ jsxs4(TokenProvider, { children: [
|
|
651
|
-
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(
|
|
652
652
|
"div",
|
|
653
653
|
{
|
|
654
654
|
style: showIFrame ? { display: "block" } : { display: "none" },
|
|
655
|
-
children: /* @__PURE__ */
|
|
655
|
+
children: /* @__PURE__ */ jsx10(
|
|
656
656
|
CivicAuthIframeContainer,
|
|
657
657
|
{
|
|
658
658
|
onClose: () => setShowIFrame(false)
|
|
@@ -660,13 +660,13 @@ var AuthProvider = ({
|
|
|
660
660
|
)
|
|
661
661
|
}
|
|
662
662
|
),
|
|
663
|
-
modalIframe && (isInIframe || isRedirecting || isLoading) && /* @__PURE__ */
|
|
664
|
-
(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: [
|
|
665
665
|
"Error: ",
|
|
666
666
|
(tokenExchangeError || error).message
|
|
667
667
|
] }) }),
|
|
668
668
|
children
|
|
669
|
-
] })
|
|
669
|
+
] }) })
|
|
670
670
|
}
|
|
671
671
|
)
|
|
672
672
|
}
|
|
@@ -676,24 +676,86 @@ var AuthProvider = ({
|
|
|
676
676
|
// src/shared/CivicAuthProvider.tsx
|
|
677
677
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
678
678
|
import "@civic/auth/styles.css";
|
|
679
|
-
import { jsx as
|
|
679
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
680
680
|
var queryClient = new QueryClient();
|
|
681
681
|
var CivicAuthProvider = (_a) => {
|
|
682
682
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
683
|
-
return /* @__PURE__ */
|
|
683
|
+
return /* @__PURE__ */ jsx11(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx11(
|
|
684
684
|
AuthProvider,
|
|
685
685
|
__spreadProps(__spreadValues({}, props), {
|
|
686
686
|
pkceConsumer: new BrowserPublicClientPKCEProducer(),
|
|
687
|
-
children: /* @__PURE__ */
|
|
687
|
+
children: /* @__PURE__ */ jsx11(UserProvider, { storage: new LocalStorageAdapter(), children })
|
|
688
688
|
})
|
|
689
689
|
) });
|
|
690
690
|
};
|
|
691
691
|
|
|
692
692
|
// src/react/providers/NextAuthProvider.tsx
|
|
693
|
-
import { useEffect as
|
|
693
|
+
import { useEffect as useEffect4, useState as useState3 } from "react";
|
|
694
694
|
import { QueryClient as QueryClient2, QueryClientProvider as QueryClientProvider2 } from "@tanstack/react-query";
|
|
695
695
|
import "@civic/auth/styles.css";
|
|
696
|
-
|
|
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";
|
|
697
759
|
var queryClient2 = new QueryClient2();
|
|
698
760
|
var CivicNextAuthProvider = (_a) => {
|
|
699
761
|
var _b = _a, {
|
|
@@ -703,31 +765,37 @@ var CivicNextAuthProvider = (_a) => {
|
|
|
703
765
|
]);
|
|
704
766
|
const [redirectUrl, setRedirectUrl] = useState3("");
|
|
705
767
|
const { clientId, oauthServer, callbackUrl, challengeUrl, logoutUrl } = resolveAuthConfig();
|
|
706
|
-
|
|
768
|
+
useEffect4(() => {
|
|
707
769
|
if (typeof globalThis.window !== "undefined") {
|
|
708
770
|
const currentUrl = globalThis.window.location.href;
|
|
709
771
|
setRedirectUrl(resolveCallbackUrl(resolveAuthConfig(), currentUrl));
|
|
710
772
|
}
|
|
711
773
|
}, [callbackUrl]);
|
|
712
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 } : {});
|
|
713
780
|
const signOut = () => __async(void 0, null, function* () {
|
|
714
781
|
var _a2;
|
|
715
|
-
yield fetch(logoutUrl);
|
|
716
782
|
(_a2 = props.onSignOut) == null ? void 0 : _a2.call(props);
|
|
783
|
+
window.location.href = logoutUrl;
|
|
717
784
|
return;
|
|
718
785
|
});
|
|
719
|
-
return /* @__PURE__ */
|
|
786
|
+
return /* @__PURE__ */ jsx12(QueryClientProvider2, { client: queryClient2, children: /* @__PURE__ */ jsx12(
|
|
720
787
|
AuthProvider,
|
|
721
788
|
__spreadProps(__spreadValues({}, props), {
|
|
722
789
|
redirectUrl,
|
|
723
790
|
config: { oauthServer },
|
|
724
791
|
clientId,
|
|
725
792
|
pkceConsumer: new ConfidentialClientPKCEConsumer(challengeUrl),
|
|
726
|
-
|
|
793
|
+
sessionData,
|
|
794
|
+
children: /* @__PURE__ */ jsx12(
|
|
727
795
|
UserProvider,
|
|
728
796
|
{
|
|
729
797
|
storage: new NextjsClientStorage(),
|
|
730
|
-
user,
|
|
798
|
+
user: combinedUser,
|
|
731
799
|
signOut,
|
|
732
800
|
children
|
|
733
801
|
}
|
|
@@ -746,38 +814,21 @@ var useUser = () => {
|
|
|
746
814
|
};
|
|
747
815
|
|
|
748
816
|
// src/react/hooks/useUserCookie.ts
|
|
749
|
-
import { useEffect as
|
|
750
|
-
import { useRouter } from "next/navigation.js";
|
|
751
|
-
import { useQuery as
|
|
752
|
-
|
|
753
|
-
// src/lib/cookies.ts
|
|
754
|
-
var getCookieValue = (key, window2) => {
|
|
755
|
-
const cookie = window2.document.cookie;
|
|
756
|
-
if (!cookie) return null;
|
|
757
|
-
const cookies = cookie.split(";");
|
|
758
|
-
for (const c of cookies) {
|
|
759
|
-
const [name, value] = c.trim().split("=");
|
|
760
|
-
if (value && name === key) {
|
|
761
|
-
try {
|
|
762
|
-
return JSON.parse(decodeURIComponent(value));
|
|
763
|
-
} catch (e) {
|
|
764
|
-
console.log("Error parsing cookie value", e);
|
|
765
|
-
return value;
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
return null;
|
|
770
|
-
};
|
|
771
|
-
|
|
772
|
-
// 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";
|
|
773
820
|
var getUserFromCookie = () => {
|
|
774
|
-
const userCookie =
|
|
821
|
+
const userCookie = getWindowCookieValue({
|
|
822
|
+
key: "user" /* USER */,
|
|
823
|
+
window: globalThis.window,
|
|
824
|
+
parseJson: true
|
|
825
|
+
});
|
|
775
826
|
return userCookie;
|
|
776
827
|
};
|
|
777
828
|
var useUserCookie = () => {
|
|
778
|
-
const hasRunRef =
|
|
779
|
-
const router =
|
|
780
|
-
const { data: user } =
|
|
829
|
+
const hasRunRef = useRef4(false);
|
|
830
|
+
const router = useRouter2();
|
|
831
|
+
const { data: user } = useQuery4({
|
|
781
832
|
queryKey: ["user"],
|
|
782
833
|
queryFn: () => getUserFromCookie(),
|
|
783
834
|
refetchInterval: 2e3,
|
|
@@ -785,7 +836,7 @@ var useUserCookie = () => {
|
|
|
785
836
|
enabled: !hasRunRef.current,
|
|
786
837
|
refetchOnWindowFocus: true
|
|
787
838
|
});
|
|
788
|
-
|
|
839
|
+
useEffect5(() => {
|
|
789
840
|
if (user) {
|
|
790
841
|
if (!hasRunRef.current) {
|
|
791
842
|
hasRunRef.current = true;
|
|
@@ -795,7 +846,7 @@ var useUserCookie = () => {
|
|
|
795
846
|
hasRunRef.current = false;
|
|
796
847
|
}
|
|
797
848
|
}, [user, router]);
|
|
798
|
-
return user;
|
|
849
|
+
return user != null ? user : null;
|
|
799
850
|
};
|
|
800
851
|
|
|
801
852
|
// src/react/hooks/useConfig.tsx
|
|
@@ -808,10 +859,20 @@ var useConfig = () => {
|
|
|
808
859
|
return context;
|
|
809
860
|
};
|
|
810
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
|
+
|
|
811
872
|
// src/react/components/UserButton.tsx
|
|
812
|
-
import { useCallback as useCallback3, useEffect as
|
|
813
|
-
import { jsx as
|
|
814
|
-
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(
|
|
815
876
|
"svg",
|
|
816
877
|
{
|
|
817
878
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -824,10 +885,10 @@ var ChevronDown = () => /* @__PURE__ */ jsx12(
|
|
|
824
885
|
strokeLinecap: "round",
|
|
825
886
|
strokeLinejoin: "round",
|
|
826
887
|
className: "lucide lucide-chevron-down",
|
|
827
|
-
children: /* @__PURE__ */
|
|
888
|
+
children: /* @__PURE__ */ jsx13("path", { d: "m6 9 6 6 6-6" })
|
|
828
889
|
}
|
|
829
890
|
);
|
|
830
|
-
var ChevronUp = () => /* @__PURE__ */
|
|
891
|
+
var ChevronUp = () => /* @__PURE__ */ jsx13(
|
|
831
892
|
"svg",
|
|
832
893
|
{
|
|
833
894
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -840,7 +901,7 @@ var ChevronUp = () => /* @__PURE__ */ jsx12(
|
|
|
840
901
|
strokeLinecap: "round",
|
|
841
902
|
strokeLinejoin: "round",
|
|
842
903
|
className: "lucide lucide-chevron-up",
|
|
843
|
-
children: /* @__PURE__ */
|
|
904
|
+
children: /* @__PURE__ */ jsx13("path", { d: "m18 15-6-6-6 6" })
|
|
844
905
|
}
|
|
845
906
|
);
|
|
846
907
|
var UserButton = ({
|
|
@@ -868,7 +929,7 @@ var UserButton = ({
|
|
|
868
929
|
setIsOpen(false);
|
|
869
930
|
}
|
|
870
931
|
}, []);
|
|
871
|
-
|
|
932
|
+
useEffect6(() => {
|
|
872
933
|
if (isOpen) {
|
|
873
934
|
window.addEventListener("click", handleClickOutside);
|
|
874
935
|
window.addEventListener("keydown", handleEscape);
|
|
@@ -889,24 +950,24 @@ var UserButton = ({
|
|
|
889
950
|
),
|
|
890
951
|
onClick: () => setIsOpen((isOpen2) => !isOpen2),
|
|
891
952
|
children: [
|
|
892
|
-
(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(
|
|
893
954
|
"img",
|
|
894
955
|
{
|
|
895
956
|
className: "cac-h-full cac-w-full cac-object-cover",
|
|
896
957
|
src: user.picture,
|
|
897
958
|
alt: (user == null ? void 0 : user.name) || (user == null ? void 0 : user.email)
|
|
898
959
|
}
|
|
899
|
-
) }) : /* @__PURE__ */
|
|
900
|
-
/* @__PURE__ */
|
|
901
|
-
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, {})
|
|
902
963
|
]
|
|
903
964
|
}
|
|
904
965
|
),
|
|
905
|
-
/* @__PURE__ */
|
|
966
|
+
/* @__PURE__ */ jsx13(
|
|
906
967
|
"div",
|
|
907
968
|
{
|
|
908
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",
|
|
909
|
-
children: /* @__PURE__ */
|
|
970
|
+
children: /* @__PURE__ */ jsx13("ul", { children: /* @__PURE__ */ jsx13("li", { children: /* @__PURE__ */ jsx13(
|
|
910
971
|
"button",
|
|
911
972
|
{
|
|
912
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",
|
|
@@ -918,7 +979,7 @@ var UserButton = ({
|
|
|
918
979
|
)
|
|
919
980
|
] });
|
|
920
981
|
}
|
|
921
|
-
return /* @__PURE__ */
|
|
982
|
+
return /* @__PURE__ */ jsx13(
|
|
922
983
|
"button",
|
|
923
984
|
{
|
|
924
985
|
"data-testid": "sign-in-button",
|
|
@@ -933,13 +994,13 @@ var UserButton = ({
|
|
|
933
994
|
};
|
|
934
995
|
|
|
935
996
|
// src/react/components/SignInButton.tsx
|
|
936
|
-
import { jsx as
|
|
997
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
937
998
|
var SignInButton = ({
|
|
938
999
|
displayMode,
|
|
939
1000
|
className
|
|
940
1001
|
}) => {
|
|
941
1002
|
const { signIn } = useUser();
|
|
942
|
-
return /* @__PURE__ */
|
|
1003
|
+
return /* @__PURE__ */ jsx14(
|
|
943
1004
|
"button",
|
|
944
1005
|
{
|
|
945
1006
|
"data-testid": "sign-in-button",
|
|
@@ -954,10 +1015,10 @@ var SignInButton = ({
|
|
|
954
1015
|
};
|
|
955
1016
|
|
|
956
1017
|
// src/react/components/SignOutButton.tsx
|
|
957
|
-
import { jsx as
|
|
1018
|
+
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
958
1019
|
var SignOutButton = ({ className }) => {
|
|
959
1020
|
const { signOut } = useUser();
|
|
960
|
-
return /* @__PURE__ */
|
|
1021
|
+
return /* @__PURE__ */ jsx15(
|
|
961
1022
|
"button",
|
|
962
1023
|
{
|
|
963
1024
|
className: cn(
|
|
@@ -971,11 +1032,11 @@ var SignOutButton = ({ className }) => {
|
|
|
971
1032
|
};
|
|
972
1033
|
|
|
973
1034
|
// src/react/components/NextLogOut.tsx
|
|
974
|
-
import { jsx as
|
|
1035
|
+
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
975
1036
|
var NextLogOut = ({ children }) => {
|
|
976
1037
|
const config = resolveAuthConfig();
|
|
977
1038
|
const logoutUrl = `${config.logoutUrl}`;
|
|
978
|
-
return /* @__PURE__ */
|
|
1039
|
+
return /* @__PURE__ */ jsx16("a", { href: logoutUrl, children });
|
|
979
1040
|
};
|
|
980
1041
|
export {
|
|
981
1042
|
CivicAuthIframeContainer,
|
|
@@ -987,8 +1048,10 @@ export {
|
|
|
987
1048
|
UserButton,
|
|
988
1049
|
useAuth,
|
|
989
1050
|
useConfig,
|
|
1051
|
+
useIframe,
|
|
990
1052
|
useSession,
|
|
991
1053
|
useToken,
|
|
1054
|
+
useTokenCookie,
|
|
992
1055
|
useUser,
|
|
993
1056
|
useUserCookie
|
|
994
1057
|
};
|