@civic/auth 0.0.1-beta.17 → 0.0.1-beta.19
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/AuthProvider-Bj_Prt1x.d.ts +21 -0
- package/dist/AuthProvider-DUAoX4G9.d.mts +21 -0
- package/dist/{index-DTimUlkB.d.ts → UserProvider-CMLaYOUD.d.ts} +1 -2
- package/dist/{index-DvjkKpkk.d.mts → UserProvider-Cbm8MZkJ.d.mts} +1 -2
- package/dist/chunk-5UQQYXCX.js +1 -0
- package/dist/chunk-5UQQYXCX.js.map +1 -0
- package/dist/chunk-BFESCRFK.mjs +118 -0
- package/dist/chunk-BFESCRFK.mjs.map +1 -0
- package/dist/{chunk-G3P5TIO2.mjs → chunk-CBQ3HKRV.mjs} +123 -232
- package/dist/chunk-CBQ3HKRV.mjs.map +1 -0
- package/dist/{chunk-SEKF2WZX.js → chunk-CZ3AVCKD.js} +16 -71
- package/dist/chunk-CZ3AVCKD.js.map +1 -0
- package/dist/chunk-DJFTZS4P.js +118 -0
- package/dist/chunk-DJFTZS4P.js.map +1 -0
- package/dist/chunk-HTTTZ2BP.mjs +223 -0
- package/dist/chunk-HTTTZ2BP.mjs.map +1 -0
- package/dist/{chunk-RF23Q4V6.js → chunk-O2SODTR3.js} +114 -223
- package/dist/chunk-O2SODTR3.js.map +1 -0
- package/dist/chunk-O6DPCPRH.js +223 -0
- package/dist/chunk-O6DPCPRH.js.map +1 -0
- package/dist/chunk-PMJAV4JJ.mjs +1 -0
- package/dist/chunk-PMJAV4JJ.mjs.map +1 -0
- package/dist/chunk-UADVRCHY.mjs +710 -0
- package/dist/chunk-UADVRCHY.mjs.map +1 -0
- package/dist/chunk-VJVRFKDH.js +710 -0
- package/dist/chunk-VJVRFKDH.js.map +1 -0
- package/dist/{chunk-5XL2ST72.mjs → chunk-X3FQBE22.mjs} +15 -70
- package/dist/chunk-X3FQBE22.mjs.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/nextjs/client.css +335 -0
- package/dist/nextjs/client.css.map +1 -0
- package/dist/nextjs/client.d.mts +12 -0
- package/dist/nextjs/client.d.ts +12 -0
- package/dist/nextjs/client.js +179 -0
- package/dist/nextjs/client.js.map +1 -0
- package/dist/nextjs/client.mjs +179 -0
- package/dist/nextjs/client.mjs.map +1 -0
- package/dist/nextjs.d.mts +35 -7
- package/dist/nextjs.d.ts +35 -7
- package/dist/nextjs.js +130 -43
- package/dist/nextjs.js.map +1 -1
- package/dist/nextjs.mjs +117 -30
- package/dist/nextjs.mjs.map +1 -1
- package/dist/react.d.mts +7 -31
- package/dist/react.d.ts +7 -31
- package/dist/react.js +15 -835
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +47 -867
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +3 -24
- package/dist/server.d.ts +3 -24
- package/dist/server.js +4 -2
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +4 -2
- package/dist/storage-B2eAQNdv.d.ts +25 -0
- package/dist/storage-BJPUpxhm.d.mts +25 -0
- package/dist/{types-b4c1koXj.d.mts → types-Bqm9OCZN.d.mts} +5 -2
- package/dist/{types-b4c1koXj.d.ts → types-Bqm9OCZN.d.ts} +5 -2
- package/package.json +11 -2
- package/dist/chunk-5XL2ST72.mjs.map +0 -1
- package/dist/chunk-G3P5TIO2.mjs.map +0 -1
- package/dist/chunk-RF23Q4V6.js.map +0 -1
- package/dist/chunk-SEKF2WZX.js.map +0 -1
package/dist/react.mjs
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
AuthProvider,
|
|
3
|
+
CivicAuthIframeContainer,
|
|
4
|
+
UserContext,
|
|
5
|
+
UserProvider,
|
|
6
|
+
useAuth,
|
|
7
|
+
useConfig,
|
|
8
|
+
useIframe,
|
|
9
|
+
useSession,
|
|
10
|
+
useToken
|
|
11
|
+
} from "./chunk-UADVRCHY.mjs";
|
|
12
|
+
import {
|
|
13
|
+
resolveAuthConfig
|
|
14
|
+
} from "./chunk-X3FQBE22.mjs";
|
|
6
15
|
import {
|
|
7
|
-
BrowserAuthenticationInitiator,
|
|
8
|
-
BrowserAuthenticationService,
|
|
9
16
|
BrowserPublicClientPKCEProducer,
|
|
10
|
-
ConfidentialClientPKCEConsumer,
|
|
11
|
-
DEFAULT_SCOPES,
|
|
12
|
-
GenericUserSession,
|
|
13
|
-
IFRAME_ID,
|
|
14
17
|
LocalStorageAdapter,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
convertForwardedTokenFormat,
|
|
18
|
-
generateState,
|
|
19
|
-
getUser,
|
|
20
|
-
isWindowInIframe
|
|
21
|
-
} from "./chunk-G3P5TIO2.mjs";
|
|
18
|
+
cn
|
|
19
|
+
} from "./chunk-CBQ3HKRV.mjs";
|
|
22
20
|
import {
|
|
23
21
|
__async,
|
|
24
22
|
__objRest,
|
|
@@ -27,852 +25,37 @@ import {
|
|
|
27
25
|
} from "./chunk-RGHW4PYM.mjs";
|
|
28
26
|
|
|
29
27
|
// src/react/hooks/useUser.tsx
|
|
30
|
-
import { useContext as useContext4 } from "react";
|
|
31
|
-
|
|
32
|
-
// src/shared/UserProvider.tsx
|
|
33
|
-
import { createContext as createContext4 } from "react";
|
|
34
|
-
import { useQuery } from "@tanstack/react-query";
|
|
35
|
-
|
|
36
|
-
// src/react/hooks/useAuth.tsx
|
|
37
28
|
import { useContext } from "react";
|
|
38
29
|
|
|
39
|
-
// src/shared/AuthContext.tsx
|
|
40
|
-
import { createContext } from "react";
|
|
41
|
-
var AuthContext = createContext(null);
|
|
42
|
-
|
|
43
|
-
// src/react/hooks/useAuth.tsx
|
|
44
|
-
var useAuth = () => {
|
|
45
|
-
const context = useContext(AuthContext);
|
|
46
|
-
if (!context) {
|
|
47
|
-
throw new Error("useAuth must be used within an AuthProvider");
|
|
48
|
-
}
|
|
49
|
-
return context;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// src/react/hooks/useToken.tsx
|
|
53
|
-
import { useContext as useContext3 } from "react";
|
|
54
|
-
|
|
55
|
-
// src/react/providers/TokenProvider.tsx
|
|
56
|
-
import { createContext as createContext3, useMemo } from "react";
|
|
57
|
-
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
58
|
-
|
|
59
|
-
// src/react/hooks/useSession.tsx
|
|
60
|
-
import { useContext as useContext2 } from "react";
|
|
61
|
-
|
|
62
|
-
// src/react/providers/SessionProvider.tsx
|
|
63
|
-
import { createContext as createContext2 } from "react";
|
|
64
|
-
import { jsx } from "react/jsx-runtime";
|
|
65
|
-
var defaultSession = {
|
|
66
|
-
authenticated: false,
|
|
67
|
-
idToken: void 0,
|
|
68
|
-
accessToken: void 0,
|
|
69
|
-
displayMode: "iframe"
|
|
70
|
-
};
|
|
71
|
-
var SessionContext = createContext2(defaultSession);
|
|
72
|
-
var SessionProvider = ({ children, session }) => /* @__PURE__ */ jsx(SessionContext.Provider, { value: __spreadValues(__spreadValues({}, defaultSession), session || {}), children });
|
|
73
|
-
|
|
74
|
-
// src/react/hooks/useSession.tsx
|
|
75
|
-
var useSession = () => {
|
|
76
|
-
const context = useContext2(SessionContext);
|
|
77
|
-
if (!context) {
|
|
78
|
-
throw new Error("useSession must be used within an SessionProvider");
|
|
79
|
-
}
|
|
80
|
-
return context;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// src/react/providers/TokenProvider.tsx
|
|
84
|
-
import { parseJWT } from "oslo/jwt";
|
|
85
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
86
|
-
var TokenContext = createContext3(void 0);
|
|
87
|
-
var TokenProvider = ({ children }) => {
|
|
88
|
-
const { isLoading, error: authError } = useAuth();
|
|
89
|
-
const session = useSession();
|
|
90
|
-
const queryClient3 = useQueryClient();
|
|
91
|
-
const refreshTokenMutation = useMutation({
|
|
92
|
-
mutationFn: () => __async(void 0, null, function* () {
|
|
93
|
-
throw new Error("Method not implemented.");
|
|
94
|
-
}),
|
|
95
|
-
onSuccess: () => {
|
|
96
|
-
queryClient3.invalidateQueries({ queryKey: ["session"] });
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
const decodeTokens = useMemo(() => {
|
|
100
|
-
if (!(session == null ? void 0 : session.idToken)) return null;
|
|
101
|
-
const parsedJWT = parseJWT(session.idToken);
|
|
102
|
-
if (!parsedJWT) return null;
|
|
103
|
-
const { forwardedTokens } = parsedJWT.payload;
|
|
104
|
-
return forwardedTokens ? convertForwardedTokenFormat(forwardedTokens) : null;
|
|
105
|
-
}, [session == null ? void 0 : session.idToken]);
|
|
106
|
-
const value = useMemo(
|
|
107
|
-
() => ({
|
|
108
|
-
accessToken: session.accessToken || null,
|
|
109
|
-
idToken: session.idToken || null,
|
|
110
|
-
forwardedTokens: decodeTokens || {},
|
|
111
|
-
refreshToken: refreshTokenMutation.mutateAsync,
|
|
112
|
-
isLoading,
|
|
113
|
-
error: authError || refreshTokenMutation.error
|
|
114
|
-
}),
|
|
115
|
-
[
|
|
116
|
-
session.accessToken,
|
|
117
|
-
session.idToken,
|
|
118
|
-
decodeTokens,
|
|
119
|
-
refreshTokenMutation.mutateAsync,
|
|
120
|
-
refreshTokenMutation.error,
|
|
121
|
-
isLoading,
|
|
122
|
-
authError
|
|
123
|
-
]
|
|
124
|
-
);
|
|
125
|
-
return /* @__PURE__ */ jsx2(TokenContext.Provider, { value, children });
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
// src/react/hooks/useToken.tsx
|
|
129
|
-
var useToken = () => {
|
|
130
|
-
const context = useContext3(TokenContext);
|
|
131
|
-
if (!context) {
|
|
132
|
-
throw new Error("useToken must be used within a TokenProvider");
|
|
133
|
-
}
|
|
134
|
-
return context;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
// src/shared/UserProvider.tsx
|
|
138
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
139
|
-
var UserContext = createContext4(null);
|
|
140
|
-
var UserProvider = ({
|
|
141
|
-
children,
|
|
142
|
-
storage,
|
|
143
|
-
user: inputUser,
|
|
144
|
-
signOut: inputSignOut
|
|
145
|
-
}) => {
|
|
146
|
-
var _a;
|
|
147
|
-
const { isLoading: authLoading, error: authError } = useAuth();
|
|
148
|
-
const session = useSession();
|
|
149
|
-
const { accessToken } = useToken();
|
|
150
|
-
const { signIn, signOut } = useAuth();
|
|
151
|
-
const fetchUser = () => __async(void 0, null, function* () {
|
|
152
|
-
if (!accessToken) {
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
const userSession = new GenericUserSession(storage);
|
|
156
|
-
return userSession.get();
|
|
157
|
-
});
|
|
158
|
-
const {
|
|
159
|
-
data: user,
|
|
160
|
-
isLoading: userLoading,
|
|
161
|
-
error: userError
|
|
162
|
-
} = useQuery({
|
|
163
|
-
queryKey: ["user", session == null ? void 0 : session.idToken],
|
|
164
|
-
queryFn: fetchUser,
|
|
165
|
-
enabled: !!(session == null ? void 0 : session.idToken)
|
|
166
|
-
// Only run the query if we have an access token
|
|
167
|
-
});
|
|
168
|
-
const isLoading = authLoading || userLoading;
|
|
169
|
-
const error = authError || userError;
|
|
170
|
-
return /* @__PURE__ */ jsx3(
|
|
171
|
-
UserContext.Provider,
|
|
172
|
-
{
|
|
173
|
-
value: {
|
|
174
|
-
user: (_a = inputUser || user) != null ? _a : null,
|
|
175
|
-
isLoading,
|
|
176
|
-
error,
|
|
177
|
-
signIn,
|
|
178
|
-
signOut: inputSignOut || signOut
|
|
179
|
-
},
|
|
180
|
-
children
|
|
181
|
-
}
|
|
182
|
-
);
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
// src/shared/AuthProvider.tsx
|
|
186
|
-
import {
|
|
187
|
-
useCallback as useCallback2,
|
|
188
|
-
useEffect as useEffect2,
|
|
189
|
-
useMemo as useMemo2,
|
|
190
|
-
useRef as useRef2,
|
|
191
|
-
useState as useState2
|
|
192
|
-
} from "react";
|
|
193
|
-
import { useMutation as useMutation2, useQuery as useQuery2, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
|
|
194
|
-
|
|
195
|
-
// src/react/components/CivicAuthIframeContainer.tsx
|
|
196
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
197
|
-
|
|
198
|
-
// src/react/components/LoadingIcon.tsx
|
|
199
|
-
import { jsx as jsx4, jsxs } from "react/jsx-runtime";
|
|
200
|
-
var LoadingIcon = () => /* @__PURE__ */ jsxs("div", { role: "status", children: [
|
|
201
|
-
/* @__PURE__ */ jsxs(
|
|
202
|
-
"svg",
|
|
203
|
-
{
|
|
204
|
-
"aria-hidden": "true",
|
|
205
|
-
className: "cac-inline cac-h-8 cac-w-8 cac-animate-spin cac-fill-neutral-600 cac-text-neutral-200 dark:cac-fill-neutral-300 dark:cac-text-neutral-600",
|
|
206
|
-
viewBox: "0 0 100 101",
|
|
207
|
-
fill: "none",
|
|
208
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
209
|
-
children: [
|
|
210
|
-
/* @__PURE__ */ jsx4(
|
|
211
|
-
"path",
|
|
212
|
-
{
|
|
213
|
-
d: "M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",
|
|
214
|
-
fill: "currentColor"
|
|
215
|
-
}
|
|
216
|
-
),
|
|
217
|
-
/* @__PURE__ */ jsx4(
|
|
218
|
-
"path",
|
|
219
|
-
{
|
|
220
|
-
d: "M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",
|
|
221
|
-
fill: "currentFill"
|
|
222
|
-
}
|
|
223
|
-
)
|
|
224
|
-
]
|
|
225
|
-
}
|
|
226
|
-
),
|
|
227
|
-
/* @__PURE__ */ jsx4("span", { className: "cac-sr-only", children: "Loading..." })
|
|
228
|
-
] });
|
|
229
|
-
|
|
230
|
-
// src/react/components/CloseIcon.tsx
|
|
231
|
-
import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
232
|
-
var CloseIcon = () => /* @__PURE__ */ jsxs2(
|
|
233
|
-
"svg",
|
|
234
|
-
{
|
|
235
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
236
|
-
width: "24",
|
|
237
|
-
height: "24",
|
|
238
|
-
viewBox: "0 0 24 24",
|
|
239
|
-
fill: "none",
|
|
240
|
-
stroke: "currentColor",
|
|
241
|
-
strokeWidth: "2",
|
|
242
|
-
strokeLinecap: "round",
|
|
243
|
-
strokeLinejoin: "round",
|
|
244
|
-
className: "lucide lucide-x",
|
|
245
|
-
children: [
|
|
246
|
-
/* @__PURE__ */ jsx5("path", { d: "M18 6 6 18" }),
|
|
247
|
-
/* @__PURE__ */ jsx5("path", { d: "m6 6 12 12" })
|
|
248
|
-
]
|
|
249
|
-
}
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
// src/react/components/CivicAuthIframe.tsx
|
|
253
|
-
import { forwardRef } from "react";
|
|
254
|
-
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
255
|
-
var CivicAuthIframe = forwardRef(
|
|
256
|
-
({ onLoad }, ref) => {
|
|
257
|
-
return /* @__PURE__ */ jsx6(
|
|
258
|
-
"iframe",
|
|
259
|
-
{
|
|
260
|
-
id: IFRAME_ID,
|
|
261
|
-
ref,
|
|
262
|
-
className: "cac-h-[26rem] cac-w-80 cac-border-none",
|
|
263
|
-
onLoad
|
|
264
|
-
}
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
);
|
|
268
|
-
CivicAuthIframe.displayName = "CivicAuthIframe";
|
|
269
|
-
|
|
270
|
-
// src/react/components/CivicAuthIframeContainer.tsx
|
|
271
|
-
import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
272
|
-
function NoChrome({
|
|
273
|
-
children
|
|
274
|
-
}) {
|
|
275
|
-
return /* @__PURE__ */ jsx7("div", { className: "cac-relative", children });
|
|
276
|
-
}
|
|
277
|
-
function IframeChrome({
|
|
278
|
-
children,
|
|
279
|
-
onClose
|
|
280
|
-
}) {
|
|
281
|
-
return /* @__PURE__ */ jsx7(
|
|
282
|
-
"div",
|
|
283
|
-
{
|
|
284
|
-
className: "cac-absolute 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-neutral-950 cac-bg-opacity-50",
|
|
285
|
-
onClick: onClose,
|
|
286
|
-
children: /* @__PURE__ */ jsxs3(
|
|
287
|
-
"div",
|
|
288
|
-
{
|
|
289
|
-
className: "cac-relative cac-rounded-3xl cac-bg-white cac-p-6 cac-shadow-lg",
|
|
290
|
-
onClick: (e) => e.stopPropagation(),
|
|
291
|
-
children: [
|
|
292
|
-
/* @__PURE__ */ jsx7(
|
|
293
|
-
"button",
|
|
294
|
-
{
|
|
295
|
-
className: "cac-absolute cac-right-4 cac-top-4 cac-flex cac-cursor-pointer cac-items-center cac-justify-center cac-border-none cac-bg-transparent cac-p-1 cac-text-neutral-400",
|
|
296
|
-
onClick: onClose,
|
|
297
|
-
children: /* @__PURE__ */ jsx7(CloseIcon, {})
|
|
298
|
-
}
|
|
299
|
-
),
|
|
300
|
-
children
|
|
301
|
-
]
|
|
302
|
-
}
|
|
303
|
-
)
|
|
304
|
-
}
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
var CivicAuthIframeContainer = ({
|
|
308
|
-
onClose,
|
|
309
|
-
closeOnRedirect = true
|
|
310
|
-
}) => {
|
|
311
|
-
var _a;
|
|
312
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
313
|
-
const { isLoading: isAuthLoading } = useAuth();
|
|
314
|
-
const config = useConfig();
|
|
315
|
-
const { setAuthResponseUrl, iframeRef } = useIframe();
|
|
316
|
-
const processIframeUrl = useCallback(() => {
|
|
317
|
-
if (iframeRef && iframeRef.current && iframeRef.current.contentWindow) {
|
|
318
|
-
try {
|
|
319
|
-
const iframeUrl = iframeRef.current.contentWindow.location.href;
|
|
320
|
-
if (iframeUrl.startsWith(config.redirectUrl)) {
|
|
321
|
-
setIsLoading(true);
|
|
322
|
-
const iframeBody = iframeRef.current.contentWindow.document.body.innerHTML;
|
|
323
|
-
if (iframeBody.includes(TOKEN_EXCHANGE_TRIGGER_TEXT)) {
|
|
324
|
-
console.log(
|
|
325
|
-
`${TOKEN_EXCHANGE_TRIGGER_TEXT}, calling callback URL again...`
|
|
326
|
-
);
|
|
327
|
-
const params = new URL(iframeUrl).searchParams;
|
|
328
|
-
fetch(`${config.redirectUrl}?${params.toString()}`);
|
|
329
|
-
} else {
|
|
330
|
-
setAuthResponseUrl(iframeUrl);
|
|
331
|
-
}
|
|
332
|
-
if (closeOnRedirect) onClose == null ? void 0 : onClose();
|
|
333
|
-
return true;
|
|
334
|
-
}
|
|
335
|
-
} catch (e) {
|
|
336
|
-
console.log("Waiting for redirect...");
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return false;
|
|
340
|
-
}, [
|
|
341
|
-
closeOnRedirect,
|
|
342
|
-
config.redirectUrl,
|
|
343
|
-
iframeRef,
|
|
344
|
-
onClose,
|
|
345
|
-
setAuthResponseUrl
|
|
346
|
-
]);
|
|
347
|
-
const intervalId = useRef();
|
|
348
|
-
const handleEscape = useCallback(
|
|
349
|
-
(event) => {
|
|
350
|
-
if (event.key === "Escape") {
|
|
351
|
-
onClose == null ? void 0 : onClose();
|
|
352
|
-
}
|
|
353
|
-
},
|
|
354
|
-
[onClose]
|
|
355
|
-
);
|
|
356
|
-
useEffect(() => {
|
|
357
|
-
window.addEventListener("keydown", handleEscape);
|
|
358
|
-
return () => window.removeEventListener("keydown", handleEscape);
|
|
359
|
-
});
|
|
360
|
-
const handleIframeLoad = () => {
|
|
361
|
-
setIsLoading(false);
|
|
362
|
-
console.log("handleIframeLoad");
|
|
363
|
-
if (processIframeUrl() && intervalId.current) {
|
|
364
|
-
clearInterval(intervalId.current);
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
const showLoadingIcon = isLoading || isAuthLoading || !((_a = iframeRef == null ? void 0 : iframeRef.current) == null ? void 0 : _a.getAttribute("src"));
|
|
368
|
-
const WrapperComponent = config.modalIframe ? IframeChrome : NoChrome;
|
|
369
|
-
return /* @__PURE__ */ jsxs3(WrapperComponent, { onClose, children: [
|
|
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, {}) }),
|
|
371
|
-
/* @__PURE__ */ jsx7(CivicAuthIframe, { ref: iframeRef, onLoad: handleIframeLoad })
|
|
372
|
-
] });
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
// src/config.ts
|
|
376
|
-
var authConfig = {
|
|
377
|
-
// TODO change this to the production URL once we're out of beta
|
|
378
|
-
oauthServer: "https://auth-dev.civic.com/oauth/"
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
// src/react/providers/ConfigProvider.tsx
|
|
382
|
-
import { createContext as createContext5 } from "react";
|
|
383
|
-
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
384
|
-
var defaultConfig = {
|
|
385
|
-
config: authConfig,
|
|
386
|
-
redirectUrl: "",
|
|
387
|
-
modalIframe: true,
|
|
388
|
-
serverTokenExchange: false
|
|
389
|
-
};
|
|
390
|
-
var ConfigContext = createContext5(defaultConfig);
|
|
391
|
-
var ConfigProvider = ({
|
|
392
|
-
children,
|
|
393
|
-
config,
|
|
394
|
-
redirectUrl,
|
|
395
|
-
modalIframe,
|
|
396
|
-
serverTokenExchange
|
|
397
|
-
}) => /* @__PURE__ */ jsx8(
|
|
398
|
-
ConfigContext.Provider,
|
|
399
|
-
{
|
|
400
|
-
value: {
|
|
401
|
-
config,
|
|
402
|
-
redirectUrl,
|
|
403
|
-
modalIframe: !!modalIframe,
|
|
404
|
-
serverTokenExchange
|
|
405
|
-
},
|
|
406
|
-
children
|
|
407
|
-
}
|
|
408
|
-
);
|
|
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
|
-
|
|
427
|
-
// src/shared/AuthProvider.tsx
|
|
428
|
-
import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
429
|
-
var globalThisObject;
|
|
430
|
-
if (typeof window !== "undefined") {
|
|
431
|
-
globalThisObject = window;
|
|
432
|
-
} else if (typeof global !== "undefined") {
|
|
433
|
-
globalThisObject = global;
|
|
434
|
-
} else {
|
|
435
|
-
globalThisObject = Function("return this")();
|
|
436
|
-
}
|
|
437
|
-
globalThisObject.globalThis = globalThisObject;
|
|
438
|
-
function BlockDisplay({ children }) {
|
|
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 }) });
|
|
440
|
-
}
|
|
441
|
-
var AuthProvider = ({
|
|
442
|
-
children,
|
|
443
|
-
clientId,
|
|
444
|
-
redirectUrl: inputRedirectUrl,
|
|
445
|
-
config = authConfig,
|
|
446
|
-
onSignIn,
|
|
447
|
-
onSignOut,
|
|
448
|
-
pkceConsumer,
|
|
449
|
-
nonce,
|
|
450
|
-
modalIframe = true,
|
|
451
|
-
sessionData: inputSessionData
|
|
452
|
-
}) => {
|
|
453
|
-
const [iframeUrl, setIframeUrl] = useState2(null);
|
|
454
|
-
const [currentUrl, setCurrentUrl] = useState2(null);
|
|
455
|
-
const [isInIframe, setIsInIframe] = useState2(false);
|
|
456
|
-
const [authResponseUrl, setAuthResponseUrl] = useState2(null);
|
|
457
|
-
const [tokenExchangeError, setTokenExchangeError] = useState2();
|
|
458
|
-
const [displayMode, setDisplayMode] = useState2("iframe");
|
|
459
|
-
const [browserAuthenticationInitiator, setBrowserAuthenticationInitiator] = useState2();
|
|
460
|
-
const [showIFrame, setShowIFrame] = useState2(false);
|
|
461
|
-
const [isRedirecting, setIsRedirecting] = useState2(false);
|
|
462
|
-
const queryClient3 = useQueryClient2();
|
|
463
|
-
const iframeRef = useRef2(null);
|
|
464
|
-
const serverTokenExchange = pkceConsumer instanceof ConfidentialClientPKCEConsumer;
|
|
465
|
-
useEffect2(() => {
|
|
466
|
-
if (typeof globalThis.window !== "undefined") {
|
|
467
|
-
setCurrentUrl(globalThis.window.location.href);
|
|
468
|
-
const isInIframeVal = isWindowInIframe(globalThis.window);
|
|
469
|
-
setIsInIframe(isInIframeVal);
|
|
470
|
-
}
|
|
471
|
-
}, []);
|
|
472
|
-
const redirectUrl = useMemo2(
|
|
473
|
-
() => (inputRedirectUrl || currentUrl || "").split("?")[0],
|
|
474
|
-
[currentUrl, inputRedirectUrl]
|
|
475
|
-
);
|
|
476
|
-
const [authService, setAuthService] = useState2();
|
|
477
|
-
useEffect2(() => {
|
|
478
|
-
if (!currentUrl) return;
|
|
479
|
-
BrowserAuthenticationService.build({
|
|
480
|
-
clientId,
|
|
481
|
-
redirectUrl,
|
|
482
|
-
oauthServer: config.oauthServer,
|
|
483
|
-
scopes: DEFAULT_SCOPES,
|
|
484
|
-
displayMode
|
|
485
|
-
}).then(setAuthService);
|
|
486
|
-
}, [currentUrl, clientId, redirectUrl, config, displayMode]);
|
|
487
|
-
const {
|
|
488
|
-
data: session,
|
|
489
|
-
isLoading,
|
|
490
|
-
error
|
|
491
|
-
} = useQuery2({
|
|
492
|
-
queryKey: [
|
|
493
|
-
"session",
|
|
494
|
-
authResponseUrl,
|
|
495
|
-
iframeUrl,
|
|
496
|
-
currentUrl,
|
|
497
|
-
isInIframe,
|
|
498
|
-
authService
|
|
499
|
-
],
|
|
500
|
-
queryFn: () => __async(void 0, null, function* () {
|
|
501
|
-
if (!authService) {
|
|
502
|
-
return { authenticated: false };
|
|
503
|
-
}
|
|
504
|
-
if (inputSessionData) {
|
|
505
|
-
return inputSessionData;
|
|
506
|
-
}
|
|
507
|
-
const url = new URL(
|
|
508
|
-
authResponseUrl ? authResponseUrl : globalThis.window.location.href || ""
|
|
509
|
-
);
|
|
510
|
-
const existingSessionData = yield authService.validateExistingSession();
|
|
511
|
-
if (existingSessionData.authenticated) {
|
|
512
|
-
return existingSessionData;
|
|
513
|
-
}
|
|
514
|
-
const code = url.searchParams.get("code");
|
|
515
|
-
const state = url.searchParams.get("state");
|
|
516
|
-
if (!serverTokenExchange && code && state && !isInIframe) {
|
|
517
|
-
try {
|
|
518
|
-
console.log("AuthProvider useQuery code", {
|
|
519
|
-
isInIframe,
|
|
520
|
-
code,
|
|
521
|
-
state
|
|
522
|
-
});
|
|
523
|
-
yield authService.tokenExchange(code, state);
|
|
524
|
-
const clientStorage = new LocalStorageAdapter();
|
|
525
|
-
const user = yield getUser(clientStorage);
|
|
526
|
-
if (!user) {
|
|
527
|
-
throw new Error("Failed to get user info");
|
|
528
|
-
}
|
|
529
|
-
const userSession = new GenericUserSession(clientStorage);
|
|
530
|
-
userSession.set(user);
|
|
531
|
-
onSignIn == null ? void 0 : onSignIn();
|
|
532
|
-
return authService.getSessionData();
|
|
533
|
-
} catch (error2) {
|
|
534
|
-
setTokenExchangeError(error2);
|
|
535
|
-
onSignIn == null ? void 0 : onSignIn(
|
|
536
|
-
error2 instanceof Error ? error2 : new Error("Failed to sign in")
|
|
537
|
-
);
|
|
538
|
-
return { authenticated: false };
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
return existingSessionData;
|
|
542
|
-
})
|
|
543
|
-
});
|
|
544
|
-
const signOutMutation = useMutation2({
|
|
545
|
-
mutationFn: () => __async(void 0, null, function* () {
|
|
546
|
-
const authInitiator = getAuthInitiator();
|
|
547
|
-
authInitiator == null ? void 0 : authInitiator.signOut();
|
|
548
|
-
setIframeUrl(null);
|
|
549
|
-
setShowIFrame(false);
|
|
550
|
-
setAuthResponseUrl(null);
|
|
551
|
-
onSignOut == null ? void 0 : onSignOut();
|
|
552
|
-
}),
|
|
553
|
-
onSuccess: () => {
|
|
554
|
-
queryClient3.setQueryData(
|
|
555
|
-
[
|
|
556
|
-
"session",
|
|
557
|
-
authResponseUrl,
|
|
558
|
-
iframeUrl,
|
|
559
|
-
currentUrl,
|
|
560
|
-
isInIframe,
|
|
561
|
-
authService
|
|
562
|
-
],
|
|
563
|
-
null
|
|
564
|
-
);
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
const getAuthInitiator = useCallback2(
|
|
568
|
-
(overrideDisplayMode) => {
|
|
569
|
-
const useDisplayMode = overrideDisplayMode || displayMode;
|
|
570
|
-
if (!pkceConsumer) {
|
|
571
|
-
return null;
|
|
572
|
-
}
|
|
573
|
-
return browserAuthenticationInitiator || new BrowserAuthenticationInitiator({
|
|
574
|
-
pkceConsumer,
|
|
575
|
-
// generate and retrieve the challenge client-side
|
|
576
|
-
clientId,
|
|
577
|
-
redirectUrl,
|
|
578
|
-
state: generateState(useDisplayMode),
|
|
579
|
-
scopes: DEFAULT_SCOPES,
|
|
580
|
-
displayMode: useDisplayMode,
|
|
581
|
-
oauthServer: config.oauthServer,
|
|
582
|
-
// the endpoints to use for the login (if not obtained from the auth server
|
|
583
|
-
endpointOverrides: config.endpoints,
|
|
584
|
-
nonce
|
|
585
|
-
});
|
|
586
|
-
},
|
|
587
|
-
[
|
|
588
|
-
displayMode,
|
|
589
|
-
browserAuthenticationInitiator,
|
|
590
|
-
clientId,
|
|
591
|
-
redirectUrl,
|
|
592
|
-
config.oauthServer,
|
|
593
|
-
config.endpoints,
|
|
594
|
-
pkceConsumer,
|
|
595
|
-
nonce
|
|
596
|
-
]
|
|
597
|
-
);
|
|
598
|
-
const signIn = useCallback2(
|
|
599
|
-
(overrideDisplayMode = "iframe") => __async(void 0, null, function* () {
|
|
600
|
-
setDisplayMode(overrideDisplayMode);
|
|
601
|
-
const authInitiator = getAuthInitiator(overrideDisplayMode);
|
|
602
|
-
setBrowserAuthenticationInitiator(authInitiator);
|
|
603
|
-
if (overrideDisplayMode === "iframe") {
|
|
604
|
-
setShowIFrame(true);
|
|
605
|
-
} else if (overrideDisplayMode === "redirect") {
|
|
606
|
-
setIsRedirecting(true);
|
|
607
|
-
}
|
|
608
|
-
authInitiator == null ? void 0 : authInitiator.signIn(iframeRef.current);
|
|
609
|
-
}),
|
|
610
|
-
[getAuthInitiator]
|
|
611
|
-
);
|
|
612
|
-
const isAuthenticated = useMemo2(
|
|
613
|
-
() => session ? session.authenticated : false,
|
|
614
|
-
[session]
|
|
615
|
-
);
|
|
616
|
-
useQuery2({
|
|
617
|
-
queryKey: ["autoSignIn", modalIframe, redirectUrl, isAuthenticated],
|
|
618
|
-
queryFn: () => __async(void 0, null, function* () {
|
|
619
|
-
if (!modalIframe && redirectUrl && !isAuthenticated && iframeRef.current) {
|
|
620
|
-
signIn("iframe");
|
|
621
|
-
}
|
|
622
|
-
return true;
|
|
623
|
-
}),
|
|
624
|
-
refetchOnWindowFocus: false
|
|
625
|
-
});
|
|
626
|
-
const value = useMemo2(
|
|
627
|
-
() => ({
|
|
628
|
-
isLoading,
|
|
629
|
-
error,
|
|
630
|
-
signOut: () => __async(void 0, null, function* () {
|
|
631
|
-
yield signOutMutation.mutateAsync();
|
|
632
|
-
}),
|
|
633
|
-
isAuthenticated,
|
|
634
|
-
signIn
|
|
635
|
-
}),
|
|
636
|
-
[isLoading, error, signOutMutation, isAuthenticated, signIn]
|
|
637
|
-
);
|
|
638
|
-
return /* @__PURE__ */ jsx10(AuthContext.Provider, { value, children: /* @__PURE__ */ jsx10(
|
|
639
|
-
ConfigProvider,
|
|
640
|
-
{
|
|
641
|
-
config,
|
|
642
|
-
redirectUrl,
|
|
643
|
-
modalIframe,
|
|
644
|
-
serverTokenExchange,
|
|
645
|
-
children: /* @__PURE__ */ jsx10(
|
|
646
|
-
IframeProvider,
|
|
647
|
-
{
|
|
648
|
-
setAuthResponseUrl,
|
|
649
|
-
iframeRef,
|
|
650
|
-
children: /* @__PURE__ */ jsx10(SessionProvider, { session, children: /* @__PURE__ */ jsxs4(TokenProvider, { children: [
|
|
651
|
-
modalIframe && !isInIframe && !(session == null ? void 0 : session.authenticated) && /* @__PURE__ */ jsx10(
|
|
652
|
-
"div",
|
|
653
|
-
{
|
|
654
|
-
style: showIFrame ? { display: "block" } : { display: "none" },
|
|
655
|
-
children: /* @__PURE__ */ jsx10(
|
|
656
|
-
CivicAuthIframeContainer,
|
|
657
|
-
{
|
|
658
|
-
onClose: () => setShowIFrame(false)
|
|
659
|
-
}
|
|
660
|
-
)
|
|
661
|
-
}
|
|
662
|
-
),
|
|
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
|
-
"Error: ",
|
|
666
|
-
(tokenExchangeError || error).message
|
|
667
|
-
] }) }),
|
|
668
|
-
children
|
|
669
|
-
] }) })
|
|
670
|
-
}
|
|
671
|
-
)
|
|
672
|
-
}
|
|
673
|
-
) });
|
|
674
|
-
};
|
|
675
|
-
|
|
676
30
|
// src/shared/CivicAuthProvider.tsx
|
|
677
31
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
678
32
|
import "@civic/auth/styles.css";
|
|
679
|
-
import { jsx
|
|
33
|
+
import { jsx } from "react/jsx-runtime";
|
|
680
34
|
var queryClient = new QueryClient();
|
|
681
35
|
var CivicAuthProvider = (_a) => {
|
|
682
36
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
683
|
-
return /* @__PURE__ */
|
|
37
|
+
return /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx(
|
|
684
38
|
AuthProvider,
|
|
685
39
|
__spreadProps(__spreadValues({}, props), {
|
|
686
40
|
pkceConsumer: new BrowserPublicClientPKCEProducer(),
|
|
687
|
-
children: /* @__PURE__ */
|
|
688
|
-
})
|
|
689
|
-
) });
|
|
690
|
-
};
|
|
691
|
-
|
|
692
|
-
// src/react/providers/NextAuthProvider.tsx
|
|
693
|
-
import { useEffect as useEffect4, useState as useState3 } from "react";
|
|
694
|
-
import { QueryClient as QueryClient2, QueryClientProvider as QueryClientProvider2 } from "@tanstack/react-query";
|
|
695
|
-
import "@civic/auth/styles.css";
|
|
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";
|
|
759
|
-
var queryClient2 = new QueryClient2();
|
|
760
|
-
var CivicNextAuthProvider = (_a) => {
|
|
761
|
-
var _b = _a, {
|
|
762
|
-
children
|
|
763
|
-
} = _b, props = __objRest(_b, [
|
|
764
|
-
"children"
|
|
765
|
-
]);
|
|
766
|
-
const [redirectUrl, setRedirectUrl] = useState3("");
|
|
767
|
-
const { clientId, oauthServer, callbackUrl, challengeUrl, logoutUrl } = resolveAuthConfig();
|
|
768
|
-
useEffect4(() => {
|
|
769
|
-
if (typeof globalThis.window !== "undefined") {
|
|
770
|
-
const currentUrl = globalThis.window.location.href;
|
|
771
|
-
setRedirectUrl(resolveCallbackUrl(resolveAuthConfig(), currentUrl));
|
|
772
|
-
}
|
|
773
|
-
}, [callbackUrl]);
|
|
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 } : {});
|
|
780
|
-
const signOut = () => __async(void 0, null, function* () {
|
|
781
|
-
var _a2;
|
|
782
|
-
(_a2 = props.onSignOut) == null ? void 0 : _a2.call(props);
|
|
783
|
-
window.location.href = logoutUrl;
|
|
784
|
-
return;
|
|
785
|
-
});
|
|
786
|
-
return /* @__PURE__ */ jsx12(QueryClientProvider2, { client: queryClient2, children: /* @__PURE__ */ jsx12(
|
|
787
|
-
AuthProvider,
|
|
788
|
-
__spreadProps(__spreadValues({}, props), {
|
|
789
|
-
redirectUrl,
|
|
790
|
-
config: { oauthServer },
|
|
791
|
-
clientId,
|
|
792
|
-
pkceConsumer: new ConfidentialClientPKCEConsumer(challengeUrl),
|
|
793
|
-
sessionData,
|
|
794
|
-
children: /* @__PURE__ */ jsx12(
|
|
795
|
-
UserProvider,
|
|
796
|
-
{
|
|
797
|
-
storage: new NextjsClientStorage(),
|
|
798
|
-
user: combinedUser,
|
|
799
|
-
signOut,
|
|
800
|
-
children
|
|
801
|
-
}
|
|
802
|
-
)
|
|
41
|
+
children: /* @__PURE__ */ jsx(UserProvider, { storage: new LocalStorageAdapter(), children })
|
|
803
42
|
})
|
|
804
43
|
) });
|
|
805
44
|
};
|
|
806
45
|
|
|
807
46
|
// src/react/hooks/useUser.tsx
|
|
808
47
|
var useUser = () => {
|
|
809
|
-
const context =
|
|
48
|
+
const context = useContext(UserContext);
|
|
810
49
|
if (!context) {
|
|
811
50
|
throw new Error("useUser must be used within a UserProvider");
|
|
812
51
|
}
|
|
813
52
|
return context;
|
|
814
53
|
};
|
|
815
54
|
|
|
816
|
-
// 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";
|
|
820
|
-
var getUserFromCookie = () => {
|
|
821
|
-
const userCookie = getWindowCookieValue({
|
|
822
|
-
key: "user" /* USER */,
|
|
823
|
-
window: globalThis.window,
|
|
824
|
-
parseJson: true
|
|
825
|
-
});
|
|
826
|
-
return userCookie;
|
|
827
|
-
};
|
|
828
|
-
var useUserCookie = () => {
|
|
829
|
-
const hasRunRef = useRef4(false);
|
|
830
|
-
const router = useRouter2();
|
|
831
|
-
const { data: user } = useQuery4({
|
|
832
|
-
queryKey: ["user"],
|
|
833
|
-
queryFn: () => getUserFromCookie(),
|
|
834
|
-
refetchInterval: 2e3,
|
|
835
|
-
refetchIntervalInBackground: true,
|
|
836
|
-
enabled: !hasRunRef.current,
|
|
837
|
-
refetchOnWindowFocus: true
|
|
838
|
-
});
|
|
839
|
-
useEffect5(() => {
|
|
840
|
-
if (user) {
|
|
841
|
-
if (!hasRunRef.current) {
|
|
842
|
-
hasRunRef.current = true;
|
|
843
|
-
router.refresh();
|
|
844
|
-
}
|
|
845
|
-
} else {
|
|
846
|
-
hasRunRef.current = false;
|
|
847
|
-
}
|
|
848
|
-
}, [user, router]);
|
|
849
|
-
return user != null ? user : null;
|
|
850
|
-
};
|
|
851
|
-
|
|
852
|
-
// src/react/hooks/useConfig.tsx
|
|
853
|
-
import { useContext as useContext5 } from "react";
|
|
854
|
-
var useConfig = () => {
|
|
855
|
-
const context = useContext5(ConfigContext);
|
|
856
|
-
if (!context) {
|
|
857
|
-
throw new Error("useConfig must be used within an ConfigProvider");
|
|
858
|
-
}
|
|
859
|
-
return context;
|
|
860
|
-
};
|
|
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
|
-
|
|
872
55
|
// src/react/components/UserButton.tsx
|
|
873
|
-
import { useCallback
|
|
874
|
-
import { jsx as
|
|
875
|
-
var ChevronDown = () => /* @__PURE__ */
|
|
56
|
+
import { useCallback, useEffect, useState } from "react";
|
|
57
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
58
|
+
var ChevronDown = () => /* @__PURE__ */ jsx2(
|
|
876
59
|
"svg",
|
|
877
60
|
{
|
|
878
61
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -885,10 +68,10 @@ var ChevronDown = () => /* @__PURE__ */ jsx13(
|
|
|
885
68
|
strokeLinecap: "round",
|
|
886
69
|
strokeLinejoin: "round",
|
|
887
70
|
className: "lucide lucide-chevron-down",
|
|
888
|
-
children: /* @__PURE__ */
|
|
71
|
+
children: /* @__PURE__ */ jsx2("path", { d: "m6 9 6 6 6-6" })
|
|
889
72
|
}
|
|
890
73
|
);
|
|
891
|
-
var ChevronUp = () => /* @__PURE__ */
|
|
74
|
+
var ChevronUp = () => /* @__PURE__ */ jsx2(
|
|
892
75
|
"svg",
|
|
893
76
|
{
|
|
894
77
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -901,35 +84,35 @@ var ChevronUp = () => /* @__PURE__ */ jsx13(
|
|
|
901
84
|
strokeLinecap: "round",
|
|
902
85
|
strokeLinejoin: "round",
|
|
903
86
|
className: "lucide lucide-chevron-up",
|
|
904
|
-
children: /* @__PURE__ */
|
|
87
|
+
children: /* @__PURE__ */ jsx2("path", { d: "m18 15-6-6-6 6" })
|
|
905
88
|
}
|
|
906
89
|
);
|
|
907
90
|
var UserButton = ({
|
|
908
91
|
displayMode,
|
|
909
92
|
className
|
|
910
93
|
}) => {
|
|
911
|
-
const [isOpen, setIsOpen] =
|
|
94
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
912
95
|
const { user, signIn, signOut } = useUser();
|
|
913
|
-
const handleClickOutside =
|
|
96
|
+
const handleClickOutside = useCallback((event) => {
|
|
914
97
|
const target = event.target;
|
|
915
98
|
if (!target.closest("#civic-dropdown-container")) {
|
|
916
99
|
setIsOpen(false);
|
|
917
100
|
}
|
|
918
101
|
}, []);
|
|
919
|
-
const handleSignOut =
|
|
102
|
+
const handleSignOut = useCallback(() => __async(void 0, null, function* () {
|
|
920
103
|
signOut();
|
|
921
104
|
setIsOpen(false);
|
|
922
105
|
}), [signOut]);
|
|
923
|
-
const handleSignIn =
|
|
106
|
+
const handleSignIn = useCallback(() => __async(void 0, null, function* () {
|
|
924
107
|
yield signIn(displayMode);
|
|
925
108
|
setIsOpen(false);
|
|
926
109
|
}), [signIn, displayMode]);
|
|
927
|
-
const handleEscape =
|
|
110
|
+
const handleEscape = useCallback((event) => {
|
|
928
111
|
if (event.key === "Escape") {
|
|
929
112
|
setIsOpen(false);
|
|
930
113
|
}
|
|
931
114
|
}, []);
|
|
932
|
-
|
|
115
|
+
useEffect(() => {
|
|
933
116
|
if (isOpen) {
|
|
934
117
|
window.addEventListener("click", handleClickOutside);
|
|
935
118
|
window.addEventListener("keydown", handleEscape);
|
|
@@ -940,8 +123,8 @@ var UserButton = ({
|
|
|
940
123
|
};
|
|
941
124
|
}, [handleClickOutside, handleEscape, isOpen]);
|
|
942
125
|
if (user) {
|
|
943
|
-
return /* @__PURE__ */
|
|
944
|
-
/* @__PURE__ */
|
|
126
|
+
return /* @__PURE__ */ jsxs("div", { className: "cac-relative", id: "civic-dropdown-container", children: [
|
|
127
|
+
/* @__PURE__ */ jsxs(
|
|
945
128
|
"button",
|
|
946
129
|
{
|
|
947
130
|
className: cn(
|
|
@@ -950,24 +133,24 @@ var UserButton = ({
|
|
|
950
133
|
),
|
|
951
134
|
onClick: () => setIsOpen((isOpen2) => !isOpen2),
|
|
952
135
|
children: [
|
|
953
|
-
(user == null ? void 0 : user.picture) ? /* @__PURE__ */
|
|
136
|
+
(user == null ? void 0 : user.picture) ? /* @__PURE__ */ jsx2("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__ */ jsx2(
|
|
954
137
|
"img",
|
|
955
138
|
{
|
|
956
139
|
className: "cac-h-full cac-w-full cac-object-cover",
|
|
957
140
|
src: user.picture,
|
|
958
141
|
alt: (user == null ? void 0 : user.name) || (user == null ? void 0 : user.email)
|
|
959
142
|
}
|
|
960
|
-
) }) : /* @__PURE__ */
|
|
961
|
-
/* @__PURE__ */
|
|
962
|
-
isOpen ? /* @__PURE__ */
|
|
143
|
+
) }) : /* @__PURE__ */ jsx2("div", {}),
|
|
144
|
+
/* @__PURE__ */ jsx2("span", { children: (user == null ? void 0 : user.name) || (user == null ? void 0 : user.email) }),
|
|
145
|
+
isOpen ? /* @__PURE__ */ jsx2(ChevronUp, {}) : /* @__PURE__ */ jsx2(ChevronDown, {})
|
|
963
146
|
]
|
|
964
147
|
}
|
|
965
148
|
),
|
|
966
|
-
/* @__PURE__ */
|
|
149
|
+
/* @__PURE__ */ jsx2(
|
|
967
150
|
"div",
|
|
968
151
|
{
|
|
969
152
|
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",
|
|
970
|
-
children: /* @__PURE__ */
|
|
153
|
+
children: /* @__PURE__ */ jsx2("ul", { children: /* @__PURE__ */ jsx2("li", { children: /* @__PURE__ */ jsx2(
|
|
971
154
|
"button",
|
|
972
155
|
{
|
|
973
156
|
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",
|
|
@@ -979,7 +162,7 @@ var UserButton = ({
|
|
|
979
162
|
)
|
|
980
163
|
] });
|
|
981
164
|
}
|
|
982
|
-
return /* @__PURE__ */
|
|
165
|
+
return /* @__PURE__ */ jsx2(
|
|
983
166
|
"button",
|
|
984
167
|
{
|
|
985
168
|
"data-testid": "sign-in-button",
|
|
@@ -994,13 +177,13 @@ var UserButton = ({
|
|
|
994
177
|
};
|
|
995
178
|
|
|
996
179
|
// src/react/components/SignInButton.tsx
|
|
997
|
-
import { jsx as
|
|
180
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
998
181
|
var SignInButton = ({
|
|
999
182
|
displayMode,
|
|
1000
183
|
className
|
|
1001
184
|
}) => {
|
|
1002
185
|
const { signIn } = useUser();
|
|
1003
|
-
return /* @__PURE__ */
|
|
186
|
+
return /* @__PURE__ */ jsx3(
|
|
1004
187
|
"button",
|
|
1005
188
|
{
|
|
1006
189
|
"data-testid": "sign-in-button",
|
|
@@ -1015,10 +198,10 @@ var SignInButton = ({
|
|
|
1015
198
|
};
|
|
1016
199
|
|
|
1017
200
|
// src/react/components/SignOutButton.tsx
|
|
1018
|
-
import { jsx as
|
|
201
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1019
202
|
var SignOutButton = ({ className }) => {
|
|
1020
203
|
const { signOut } = useUser();
|
|
1021
|
-
return /* @__PURE__ */
|
|
204
|
+
return /* @__PURE__ */ jsx4(
|
|
1022
205
|
"button",
|
|
1023
206
|
{
|
|
1024
207
|
className: cn(
|
|
@@ -1032,16 +215,15 @@ var SignOutButton = ({ className }) => {
|
|
|
1032
215
|
};
|
|
1033
216
|
|
|
1034
217
|
// src/react/components/NextLogOut.tsx
|
|
1035
|
-
import { jsx as
|
|
218
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
1036
219
|
var NextLogOut = ({ children }) => {
|
|
1037
220
|
const config = resolveAuthConfig();
|
|
1038
221
|
const logoutUrl = `${config.logoutUrl}`;
|
|
1039
|
-
return /* @__PURE__ */
|
|
222
|
+
return /* @__PURE__ */ jsx5("a", { href: logoutUrl, children });
|
|
1040
223
|
};
|
|
1041
224
|
export {
|
|
1042
225
|
CivicAuthIframeContainer,
|
|
1043
226
|
CivicAuthProvider,
|
|
1044
|
-
CivicNextAuthProvider,
|
|
1045
227
|
NextLogOut,
|
|
1046
228
|
SignInButton,
|
|
1047
229
|
SignOutButton,
|
|
@@ -1051,8 +233,6 @@ export {
|
|
|
1051
233
|
useIframe,
|
|
1052
234
|
useSession,
|
|
1053
235
|
useToken,
|
|
1054
|
-
|
|
1055
|
-
useUser,
|
|
1056
|
-
useUserCookie
|
|
236
|
+
useUser
|
|
1057
237
|
};
|
|
1058
238
|
//# sourceMappingURL=react.mjs.map
|