@civic/auth 0.0.1-beta.18 → 0.0.1-beta.2
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/README.md +0 -26
- package/dist/chunk-5NUJ7LFF.mjs +17 -0
- package/dist/chunk-5NUJ7LFF.mjs.map +1 -0
- package/dist/chunk-KS7ERXGZ.js +481 -0
- package/dist/chunk-KS7ERXGZ.js.map +1 -0
- package/dist/chunk-NINRO7GS.js +209 -0
- package/dist/chunk-NINRO7GS.js.map +1 -0
- package/dist/chunk-NXBKSUKI.mjs +481 -0
- package/dist/chunk-NXBKSUKI.mjs.map +1 -0
- package/dist/chunk-T7HUHQ3J.mjs +209 -0
- package/dist/chunk-T7HUHQ3J.mjs.map +1 -0
- package/dist/chunk-WZLC5B4C.js +17 -0
- package/dist/chunk-WZLC5B4C.js.map +1 -0
- package/dist/index-DoDoIY_K.d.mts +79 -0
- package/dist/index-DoDoIY_K.d.ts +79 -0
- package/dist/index.css +70 -63
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/nextjs.d.mts +11 -10
- package/dist/nextjs.d.ts +11 -10
- package/dist/nextjs.js +173 -62
- package/dist/nextjs.js.map +1 -1
- package/dist/nextjs.mjs +171 -60
- package/dist/nextjs.mjs.map +1 -1
- package/dist/react.d.mts +65 -39
- package/dist/react.d.ts +65 -39
- package/dist/react.js +212 -433
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +235 -456
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +12 -13
- package/dist/server.d.ts +12 -13
- package/dist/server.js +186 -3
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +192 -9
- package/dist/server.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/chunk-5XL2ST72.mjs +0 -226
- package/dist/chunk-5XL2ST72.mjs.map +0 -1
- package/dist/chunk-G3P5TIO2.mjs +0 -708
- package/dist/chunk-G3P5TIO2.mjs.map +0 -1
- package/dist/chunk-RF23Q4V6.js +0 -708
- package/dist/chunk-RF23Q4V6.js.map +0 -1
- package/dist/chunk-SEKF2WZX.js +0 -226
- package/dist/chunk-SEKF2WZX.js.map +0 -1
- package/dist/index-DTimUlkB.d.ts +0 -17
- package/dist/index-DvjkKpkk.d.mts +0 -17
- package/dist/types-HdCjGldB.d.mts +0 -58
- package/dist/types-HdCjGldB.d.ts +0 -58
- package/dist/types-b4c1koXj.d.mts +0 -19
- package/dist/types-b4c1koXj.d.ts +0 -19
package/dist/react.js
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
var _chunkKS7ERXGZjs = require('./chunk-KS7ERXGZ.js');
|
|
4
5
|
|
|
5
|
-
var _chunkSEKF2WZXjs = require('./chunk-SEKF2WZX.js');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
var _chunkWZLC5B4Cjs = require('./chunk-WZLC5B4C.js');
|
|
8
9
|
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var _chunkRF23Q4V6js = require('./chunk-RF23Q4V6.js');
|
|
11
|
+
var _chunkNINRO7GSjs = require('./chunk-NINRO7GS.js');
|
|
22
12
|
|
|
23
13
|
|
|
24
14
|
|
|
@@ -29,7 +19,7 @@ var _chunkCRTRMMJ7js = require('./chunk-CRTRMMJ7.js');
|
|
|
29
19
|
// src/react/hooks/useUser.tsx
|
|
30
20
|
var _react = require('react');
|
|
31
21
|
|
|
32
|
-
// src/
|
|
22
|
+
// src/react/providers/UserProvider.tsx
|
|
33
23
|
|
|
34
24
|
var _reactquery = require('@tanstack/react-query');
|
|
35
25
|
|
|
@@ -69,7 +59,7 @@ var defaultSession = {
|
|
|
69
59
|
displayMode: "iframe"
|
|
70
60
|
};
|
|
71
61
|
var SessionContext = _react.createContext.call(void 0, defaultSession);
|
|
72
|
-
var SessionProvider = ({ children, session }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SessionContext.Provider, { value:
|
|
62
|
+
var SessionProvider = ({ children, session }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SessionContext.Provider, { value: session || defaultSession, children });
|
|
73
63
|
|
|
74
64
|
// src/react/hooks/useSession.tsx
|
|
75
65
|
var useSession = () => {
|
|
@@ -83,6 +73,20 @@ var useSession = () => {
|
|
|
83
73
|
// src/react/providers/TokenProvider.tsx
|
|
84
74
|
var _jwt = require('oslo/jwt');
|
|
85
75
|
|
|
76
|
+
// src/lib/jwt.ts
|
|
77
|
+
var convertForwardedTokenFormat = (inputTokens) => Object.fromEntries(
|
|
78
|
+
Object.entries(inputTokens).map(([source, tokens]) => [
|
|
79
|
+
source,
|
|
80
|
+
{
|
|
81
|
+
idToken: tokens == null ? void 0 : tokens.id_token,
|
|
82
|
+
accessToken: tokens == null ? void 0 : tokens.access_token,
|
|
83
|
+
refreshToken: tokens == null ? void 0 : tokens.refresh_token
|
|
84
|
+
}
|
|
85
|
+
])
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
// src/react/providers/TokenProvider.tsx
|
|
89
|
+
|
|
86
90
|
var TokenContext = _react.createContext.call(void 0, void 0);
|
|
87
91
|
var TokenProvider = ({ children }) => {
|
|
88
92
|
const { isLoading, error: authError } = useAuth();
|
|
@@ -101,7 +105,7 @@ var TokenProvider = ({ children }) => {
|
|
|
101
105
|
const parsedJWT = _jwt.parseJWT.call(void 0, session.idToken);
|
|
102
106
|
if (!parsedJWT) return null;
|
|
103
107
|
const { forwardedTokens } = parsedJWT.payload;
|
|
104
|
-
return forwardedTokens ?
|
|
108
|
+
return forwardedTokens ? convertForwardedTokenFormat(forwardedTokens) : null;
|
|
105
109
|
}, [session == null ? void 0 : session.idToken]);
|
|
106
110
|
const value = _react.useMemo.call(void 0,
|
|
107
111
|
() => ({
|
|
@@ -134,26 +138,31 @@ var useToken = () => {
|
|
|
134
138
|
return context;
|
|
135
139
|
};
|
|
136
140
|
|
|
137
|
-
// src/
|
|
141
|
+
// src/react/providers/UserProvider.tsx
|
|
138
142
|
|
|
139
143
|
var UserContext = _react.createContext.call(void 0, null);
|
|
140
144
|
var UserProvider = ({
|
|
141
145
|
children,
|
|
142
|
-
|
|
143
|
-
user: inputUser,
|
|
144
|
-
signOut: inputSignOut
|
|
146
|
+
userInfoService
|
|
145
147
|
}) => {
|
|
146
|
-
var _a;
|
|
147
148
|
const { isLoading: authLoading, error: authError } = useAuth();
|
|
148
149
|
const session = useSession();
|
|
149
|
-
const { accessToken } = useToken();
|
|
150
|
+
const { forwardedTokens, idToken, accessToken, refreshToken } = useToken();
|
|
150
151
|
const { signIn, signOut } = useAuth();
|
|
151
152
|
const fetchUser = () => _chunkCRTRMMJ7js.__async.call(void 0, void 0, null, function* () {
|
|
152
|
-
if (!accessToken) {
|
|
153
|
+
if (!accessToken || !userInfoService) {
|
|
153
154
|
return null;
|
|
154
155
|
}
|
|
155
|
-
const
|
|
156
|
-
|
|
156
|
+
const user2 = yield userInfoService == null ? void 0 : userInfoService.getUserInfo(accessToken, idToken);
|
|
157
|
+
if (!user2) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
return _chunkCRTRMMJ7js.__spreadProps.call(void 0, _chunkCRTRMMJ7js.__spreadValues.call(void 0, {}, user2), {
|
|
161
|
+
forwardedTokens,
|
|
162
|
+
idToken,
|
|
163
|
+
accessToken,
|
|
164
|
+
refreshToken
|
|
165
|
+
});
|
|
157
166
|
});
|
|
158
167
|
const {
|
|
159
168
|
data: user,
|
|
@@ -171,11 +180,11 @@ var UserProvider = ({
|
|
|
171
180
|
UserContext.Provider,
|
|
172
181
|
{
|
|
173
182
|
value: {
|
|
174
|
-
user:
|
|
183
|
+
user: user != null ? user : null,
|
|
175
184
|
isLoading,
|
|
176
185
|
error,
|
|
177
186
|
signIn,
|
|
178
|
-
signOut
|
|
187
|
+
signOut
|
|
179
188
|
},
|
|
180
189
|
children
|
|
181
190
|
}
|
|
@@ -192,7 +201,7 @@ var UserProvider = ({
|
|
|
192
201
|
|
|
193
202
|
|
|
194
203
|
|
|
195
|
-
// src/react/components/
|
|
204
|
+
// src/react/components/CivicAuthIframeModal.tsx
|
|
196
205
|
|
|
197
206
|
|
|
198
207
|
// src/react/components/LoadingIcon.tsx
|
|
@@ -202,7 +211,7 @@ var LoadingIcon = () => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { r
|
|
|
202
211
|
"svg",
|
|
203
212
|
{
|
|
204
213
|
"aria-hidden": "true",
|
|
205
|
-
className: "
|
|
214
|
+
className: "inline h-8 w-8 animate-spin fill-neutral-600 text-neutral-200 dark:fill-neutral-300 dark:text-neutral-600",
|
|
206
215
|
viewBox: "0 0 100 101",
|
|
207
216
|
fill: "none",
|
|
208
217
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -224,7 +233,7 @@ var LoadingIcon = () => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { r
|
|
|
224
233
|
]
|
|
225
234
|
}
|
|
226
235
|
),
|
|
227
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "
|
|
236
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "sr-only", children: "Loading..." })
|
|
228
237
|
] });
|
|
229
238
|
|
|
230
239
|
// src/react/components/CloseIcon.tsx
|
|
@@ -253,13 +262,14 @@ var CloseIcon = () => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
|
253
262
|
|
|
254
263
|
|
|
255
264
|
var CivicAuthIframe = _react.forwardRef.call(void 0,
|
|
256
|
-
({ onLoad }, ref) => {
|
|
265
|
+
({ authUrl, onLoad }, ref) => {
|
|
257
266
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
258
267
|
"iframe",
|
|
259
268
|
{
|
|
260
|
-
id:
|
|
269
|
+
id: _chunkWZLC5B4Cjs.IFRAME_ID,
|
|
261
270
|
ref,
|
|
262
|
-
|
|
271
|
+
src: authUrl,
|
|
272
|
+
className: "h-96 w-80 border-none",
|
|
263
273
|
onLoad
|
|
264
274
|
}
|
|
265
275
|
);
|
|
@@ -267,69 +277,25 @@ var CivicAuthIframe = _react.forwardRef.call(void 0,
|
|
|
267
277
|
);
|
|
268
278
|
CivicAuthIframe.displayName = "CivicAuthIframe";
|
|
269
279
|
|
|
270
|
-
// src/react/components/
|
|
280
|
+
// src/react/components/CivicAuthIframeModal.tsx
|
|
271
281
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
function IframeChrome({
|
|
278
|
-
children,
|
|
279
|
-
onClose
|
|
280
|
-
}) {
|
|
281
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
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__ */ _jsxruntime.jsxs.call(void 0,
|
|
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__ */ _jsxruntime.jsx.call(void 0,
|
|
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__ */ _jsxruntime.jsx.call(void 0, CloseIcon, {})
|
|
298
|
-
}
|
|
299
|
-
),
|
|
300
|
-
children
|
|
301
|
-
]
|
|
302
|
-
}
|
|
303
|
-
)
|
|
304
|
-
}
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
var CivicAuthIframeContainer = ({
|
|
282
|
+
var CivicAuthIframeModal = ({
|
|
283
|
+
authUrl,
|
|
284
|
+
redirectUri,
|
|
285
|
+
setAuthResponseUrl,
|
|
308
286
|
onClose,
|
|
287
|
+
iframeRef,
|
|
288
|
+
redirectInProgress = false,
|
|
309
289
|
closeOnRedirect = true
|
|
310
290
|
}) => {
|
|
311
|
-
var _a;
|
|
312
291
|
const [isLoading, setIsLoading] = _react.useState.call(void 0, true);
|
|
313
|
-
const { isLoading: isAuthLoading } = useAuth();
|
|
314
|
-
const config = useConfig();
|
|
315
|
-
const { setAuthResponseUrl, iframeRef } = useIframe();
|
|
316
292
|
const processIframeUrl = _react.useCallback.call(void 0, () => {
|
|
317
|
-
if (iframeRef
|
|
293
|
+
if (iframeRef.current && iframeRef.current.contentWindow) {
|
|
318
294
|
try {
|
|
319
295
|
const iframeUrl = iframeRef.current.contentWindow.location.href;
|
|
320
|
-
if (iframeUrl.startsWith(
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
if (iframeBody.includes(_chunkRF23Q4V6js.TOKEN_EXCHANGE_TRIGGER_TEXT)) {
|
|
324
|
-
console.log(
|
|
325
|
-
`${_chunkRF23Q4V6js.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();
|
|
296
|
+
if (iframeUrl.startsWith(redirectUri)) {
|
|
297
|
+
setAuthResponseUrl(iframeUrl);
|
|
298
|
+
if (closeOnRedirect) onClose();
|
|
333
299
|
return true;
|
|
334
300
|
}
|
|
335
301
|
} catch (e) {
|
|
@@ -337,18 +303,12 @@ var CivicAuthIframeContainer = ({
|
|
|
337
303
|
}
|
|
338
304
|
}
|
|
339
305
|
return false;
|
|
340
|
-
}, [
|
|
341
|
-
closeOnRedirect,
|
|
342
|
-
config.redirectUrl,
|
|
343
|
-
iframeRef,
|
|
344
|
-
onClose,
|
|
345
|
-
setAuthResponseUrl
|
|
346
|
-
]);
|
|
306
|
+
}, [closeOnRedirect, iframeRef, onClose, redirectUri, setAuthResponseUrl]);
|
|
347
307
|
const intervalId = _react.useRef.call(void 0, );
|
|
348
308
|
const handleEscape = _react.useCallback.call(void 0,
|
|
349
309
|
(event) => {
|
|
350
310
|
if (event.key === "Escape") {
|
|
351
|
-
onClose
|
|
311
|
+
onClose();
|
|
352
312
|
}
|
|
353
313
|
},
|
|
354
314
|
[onClose]
|
|
@@ -364,12 +324,39 @@ var CivicAuthIframeContainer = ({
|
|
|
364
324
|
clearInterval(intervalId.current);
|
|
365
325
|
}
|
|
366
326
|
};
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
327
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
328
|
+
"div",
|
|
329
|
+
{
|
|
330
|
+
className: "absolute left-0 top-0 z-50 flex h-screen w-screen items-center justify-center bg-neutral-950 bg-opacity-50",
|
|
331
|
+
onClick: onClose,
|
|
332
|
+
children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
333
|
+
"div",
|
|
334
|
+
{
|
|
335
|
+
className: "relative rounded-3xl bg-white p-6 shadow-lg",
|
|
336
|
+
onClick: (e) => e.stopPropagation(),
|
|
337
|
+
children: [
|
|
338
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
339
|
+
"button",
|
|
340
|
+
{
|
|
341
|
+
className: "absolute right-4 top-4 flex cursor-pointer items-center justify-center border-none bg-transparent p-1 text-neutral-400",
|
|
342
|
+
onClick: onClose,
|
|
343
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, CloseIcon, {})
|
|
344
|
+
}
|
|
345
|
+
),
|
|
346
|
+
(isLoading || redirectInProgress) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "absolute inset-0 flex items-center justify-center rounded-3xl bg-neutral-100", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LoadingIcon, {}) }),
|
|
347
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
348
|
+
CivicAuthIframe,
|
|
349
|
+
{
|
|
350
|
+
ref: iframeRef,
|
|
351
|
+
authUrl,
|
|
352
|
+
onLoad: handleIframeLoad
|
|
353
|
+
}
|
|
354
|
+
)
|
|
355
|
+
]
|
|
356
|
+
}
|
|
357
|
+
)
|
|
358
|
+
}
|
|
359
|
+
);
|
|
373
360
|
};
|
|
374
361
|
|
|
375
362
|
// src/config.ts
|
|
@@ -378,51 +365,20 @@ var authConfig = {
|
|
|
378
365
|
oauthServer: "https://auth-dev.civic.com/oauth/"
|
|
379
366
|
};
|
|
380
367
|
|
|
381
|
-
// src/
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
children,
|
|
393
|
-
config,
|
|
394
|
-
redirectUrl,
|
|
395
|
-
modalIframe,
|
|
396
|
-
serverTokenExchange
|
|
397
|
-
}) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
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
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
var defaultIframe = {
|
|
416
|
-
iframeRef: null,
|
|
417
|
-
setAuthResponseUrl: () => {
|
|
368
|
+
// src/lib/windowUtil.ts
|
|
369
|
+
var isWindowInIframe = (window2) => {
|
|
370
|
+
var _a;
|
|
371
|
+
if (typeof window2 !== "undefined") {
|
|
372
|
+
try {
|
|
373
|
+
if (((_a = window2 == null ? void 0 : window2.frameElement) == null ? void 0 : _a.id) === "civic-auth-iframe") {
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
} catch (_e) {
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
418
379
|
}
|
|
380
|
+
return false;
|
|
419
381
|
};
|
|
420
|
-
var IframeContext = _react.createContext.call(void 0, defaultIframe);
|
|
421
|
-
var IframeProvider = ({
|
|
422
|
-
children,
|
|
423
|
-
iframeRef,
|
|
424
|
-
setAuthResponseUrl
|
|
425
|
-
}) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, IframeContext.Provider, { value: { iframeRef, setAuthResponseUrl }, children });
|
|
426
382
|
|
|
427
383
|
// src/shared/AuthProvider.tsx
|
|
428
384
|
|
|
@@ -435,37 +391,28 @@ if (typeof window !== "undefined") {
|
|
|
435
391
|
globalThisObject = Function("return this")();
|
|
436
392
|
}
|
|
437
393
|
globalThisObject.globalThis = globalThisObject;
|
|
438
|
-
function BlockDisplay({ children }) {
|
|
439
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "cac-relative cac-left-0 cac-top-0 cac-z-50 cac-flex cac-h-screen cac-w-screen cac-items-center cac-justify-center cac-bg-white", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "cac-absolute cac-inset-0 cac-flex cac-items-center cac-justify-center cac-bg-white", children }) });
|
|
440
|
-
}
|
|
441
394
|
var AuthProvider = ({
|
|
442
395
|
children,
|
|
443
396
|
clientId,
|
|
444
397
|
redirectUrl: inputRedirectUrl,
|
|
445
398
|
config = authConfig,
|
|
399
|
+
nonce,
|
|
446
400
|
onSignIn,
|
|
447
401
|
onSignOut,
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
modalIframe = true,
|
|
451
|
-
sessionData: inputSessionData
|
|
402
|
+
authServiceImpl,
|
|
403
|
+
serverSideTokenExchange
|
|
452
404
|
}) => {
|
|
453
405
|
const [iframeUrl, setIframeUrl] = _react.useState.call(void 0, null);
|
|
454
406
|
const [currentUrl, setCurrentUrl] = _react.useState.call(void 0, null);
|
|
455
407
|
const [isInIframe, setIsInIframe] = _react.useState.call(void 0, false);
|
|
456
408
|
const [authResponseUrl, setAuthResponseUrl] = _react.useState.call(void 0, null);
|
|
457
409
|
const [tokenExchangeError, setTokenExchangeError] = _react.useState.call(void 0, );
|
|
458
|
-
const [displayMode, setDisplayMode] = _react.useState.call(void 0, "iframe");
|
|
459
|
-
const [browserAuthenticationInitiator, setBrowserAuthenticationInitiator] = _react.useState.call(void 0, );
|
|
460
|
-
const [showIFrame, setShowIFrame] = _react.useState.call(void 0, false);
|
|
461
|
-
const [isRedirecting, setIsRedirecting] = _react.useState.call(void 0, false);
|
|
462
410
|
const queryClient3 = _reactquery.useQueryClient.call(void 0, );
|
|
463
411
|
const iframeRef = _react.useRef.call(void 0, null);
|
|
464
|
-
const serverTokenExchange = pkceConsumer instanceof _chunkRF23Q4V6js.ConfidentialClientPKCEConsumer;
|
|
465
412
|
_react.useEffect.call(void 0, () => {
|
|
466
413
|
if (typeof globalThis.window !== "undefined") {
|
|
467
414
|
setCurrentUrl(globalThis.window.location.href);
|
|
468
|
-
const isInIframeVal =
|
|
415
|
+
const isInIframeVal = isWindowInIframe(globalThis.window);
|
|
469
416
|
setIsInIframe(isInIframeVal);
|
|
470
417
|
}
|
|
471
418
|
}, []);
|
|
@@ -473,63 +420,40 @@ var AuthProvider = ({
|
|
|
473
420
|
() => (inputRedirectUrl || currentUrl || "").split("?")[0],
|
|
474
421
|
[currentUrl, inputRedirectUrl]
|
|
475
422
|
);
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
if (!currentUrl) return;
|
|
479
|
-
_chunkRF23Q4V6js.BrowserAuthenticationService.build({
|
|
423
|
+
const authService = _react.useMemo.call(void 0,
|
|
424
|
+
() => currentUrl ? authServiceImpl || new (0, _chunkKS7ERXGZjs.AuthSessionServiceImpl)(
|
|
480
425
|
clientId,
|
|
481
426
|
redirectUrl,
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
427
|
+
config == null ? void 0 : config.oauthServer,
|
|
428
|
+
config == null ? void 0 : config.endpoints
|
|
429
|
+
) : null,
|
|
430
|
+
[currentUrl, clientId, redirectUrl, config, authServiceImpl]
|
|
431
|
+
);
|
|
432
|
+
const [userInfoService, setUserInfoService] = _react.useState.call(void 0, );
|
|
433
|
+
_react.useEffect.call(void 0, () => {
|
|
434
|
+
if (!authService) return;
|
|
435
|
+
authService.getUserInfoService().then(setUserInfoService);
|
|
436
|
+
}, [authService]);
|
|
487
437
|
const {
|
|
488
438
|
data: session,
|
|
489
439
|
isLoading,
|
|
490
440
|
error
|
|
491
441
|
} = _reactquery.useQuery.call(void 0, {
|
|
492
|
-
queryKey: [
|
|
493
|
-
"session",
|
|
494
|
-
authResponseUrl,
|
|
495
|
-
iframeUrl,
|
|
496
|
-
currentUrl,
|
|
497
|
-
isInIframe,
|
|
498
|
-
authService
|
|
499
|
-
],
|
|
442
|
+
queryKey: ["session", authResponseUrl, iframeUrl, currentUrl, isInIframe],
|
|
500
443
|
queryFn: () => _chunkCRTRMMJ7js.__async.call(void 0, void 0, null, function* () {
|
|
501
444
|
if (!authService) {
|
|
502
445
|
return { authenticated: false };
|
|
503
446
|
}
|
|
504
|
-
if (inputSessionData) {
|
|
505
|
-
return inputSessionData;
|
|
506
|
-
}
|
|
507
447
|
const url = new URL(
|
|
508
448
|
authResponseUrl ? authResponseUrl : globalThis.window.location.href || ""
|
|
509
449
|
);
|
|
510
|
-
const existingSessionData = yield authService.validateExistingSession();
|
|
511
|
-
if (existingSessionData.authenticated) {
|
|
512
|
-
return existingSessionData;
|
|
513
|
-
}
|
|
514
450
|
const code = url.searchParams.get("code");
|
|
515
|
-
|
|
516
|
-
if (!serverTokenExchange && code && state && !isInIframe) {
|
|
451
|
+
if (code && !isInIframe && !serverSideTokenExchange) {
|
|
517
452
|
try {
|
|
518
|
-
console.log("AuthProvider useQuery code", {
|
|
519
|
-
|
|
520
|
-
code,
|
|
521
|
-
state
|
|
522
|
-
});
|
|
523
|
-
yield authService.tokenExchange(code, state);
|
|
524
|
-
const clientStorage = new (0, _chunkRF23Q4V6js.LocalStorageAdapter)();
|
|
525
|
-
const user = yield _chunkRF23Q4V6js.getUser.call(void 0, clientStorage);
|
|
526
|
-
if (!user) {
|
|
527
|
-
throw new Error("Failed to get user info");
|
|
528
|
-
}
|
|
529
|
-
const userSession = new (0, _chunkRF23Q4V6js.GenericUserSession)(clientStorage);
|
|
530
|
-
userSession.set(user);
|
|
453
|
+
console.log("AuthProvider useQuery code", { isInIframe, code });
|
|
454
|
+
const newSession = yield authService.tokenExchange(url.toString());
|
|
531
455
|
onSignIn == null ? void 0 : onSignIn();
|
|
532
|
-
return
|
|
456
|
+
return newSession;
|
|
533
457
|
} catch (error2) {
|
|
534
458
|
setTokenExchangeError(error2);
|
|
535
459
|
onSignIn == null ? void 0 : onSignIn(
|
|
@@ -538,91 +462,48 @@ var AuthProvider = ({
|
|
|
538
462
|
return { authenticated: false };
|
|
539
463
|
}
|
|
540
464
|
}
|
|
465
|
+
const existingSessionData = yield authService.validateExistingSession();
|
|
466
|
+
if (existingSessionData.authenticated) {
|
|
467
|
+
return existingSessionData;
|
|
468
|
+
}
|
|
541
469
|
return existingSessionData;
|
|
542
470
|
})
|
|
543
471
|
});
|
|
544
472
|
const signOutMutation = _reactquery.useMutation.call(void 0, {
|
|
545
473
|
mutationFn: () => _chunkCRTRMMJ7js.__async.call(void 0, void 0, null, function* () {
|
|
546
|
-
|
|
547
|
-
authInitiator == null ? void 0 : authInitiator.signOut();
|
|
474
|
+
authService == null ? void 0 : authService.updateSessionData({});
|
|
548
475
|
setIframeUrl(null);
|
|
549
|
-
setShowIFrame(false);
|
|
550
476
|
setAuthResponseUrl(null);
|
|
551
477
|
onSignOut == null ? void 0 : onSignOut();
|
|
552
478
|
}),
|
|
553
479
|
onSuccess: () => {
|
|
554
480
|
queryClient3.setQueryData(
|
|
555
|
-
[
|
|
556
|
-
"session",
|
|
557
|
-
authResponseUrl,
|
|
558
|
-
iframeUrl,
|
|
559
|
-
currentUrl,
|
|
560
|
-
isInIframe,
|
|
561
|
-
authService
|
|
562
|
-
],
|
|
481
|
+
["session", authResponseUrl, iframeUrl, currentUrl, isInIframe],
|
|
563
482
|
null
|
|
564
483
|
);
|
|
565
484
|
}
|
|
566
485
|
});
|
|
567
|
-
const getAuthInitiator = _react.useCallback.call(void 0,
|
|
568
|
-
(overrideDisplayMode) => {
|
|
569
|
-
const useDisplayMode = overrideDisplayMode || displayMode;
|
|
570
|
-
if (!pkceConsumer) {
|
|
571
|
-
return null;
|
|
572
|
-
}
|
|
573
|
-
return browserAuthenticationInitiator || new (0, _chunkRF23Q4V6js.BrowserAuthenticationInitiator)({
|
|
574
|
-
pkceConsumer,
|
|
575
|
-
// generate and retrieve the challenge client-side
|
|
576
|
-
clientId,
|
|
577
|
-
redirectUrl,
|
|
578
|
-
state: _chunkRF23Q4V6js.generateState.call(void 0, useDisplayMode),
|
|
579
|
-
scopes: _chunkRF23Q4V6js.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
486
|
const signIn = _react.useCallback.call(void 0,
|
|
599
487
|
(overrideDisplayMode = "iframe") => _chunkCRTRMMJ7js.__async.call(void 0, void 0, null, function* () {
|
|
600
|
-
|
|
601
|
-
const
|
|
602
|
-
|
|
488
|
+
if (!authService) return;
|
|
489
|
+
const url = yield authService.getAuthorizationUrl(
|
|
490
|
+
// This is the default scope. We will eventually pull this from the partner dashboard
|
|
491
|
+
_chunkWZLC5B4Cjs.DEFAULT_SCOPES,
|
|
492
|
+
overrideDisplayMode,
|
|
493
|
+
nonce
|
|
494
|
+
);
|
|
603
495
|
if (overrideDisplayMode === "iframe") {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
setIsRedirecting(true);
|
|
496
|
+
setIframeUrl(url);
|
|
497
|
+
return;
|
|
607
498
|
}
|
|
608
|
-
|
|
499
|
+
authService.loadAuthorizationUrl(url, overrideDisplayMode);
|
|
609
500
|
}),
|
|
610
|
-
[
|
|
501
|
+
[authService, nonce]
|
|
611
502
|
);
|
|
612
503
|
const isAuthenticated = _react.useMemo.call(void 0,
|
|
613
504
|
() => session ? session.authenticated : false,
|
|
614
505
|
[session]
|
|
615
506
|
);
|
|
616
|
-
_reactquery.useQuery.call(void 0, {
|
|
617
|
-
queryKey: ["autoSignIn", modalIframe, redirectUrl, isAuthenticated],
|
|
618
|
-
queryFn: () => _chunkCRTRMMJ7js.__async.call(void 0, void 0, null, function* () {
|
|
619
|
-
if (!modalIframe && redirectUrl && !isAuthenticated && iframeRef.current) {
|
|
620
|
-
signIn("iframe");
|
|
621
|
-
}
|
|
622
|
-
return true;
|
|
623
|
-
}),
|
|
624
|
-
refetchOnWindowFocus: false
|
|
625
|
-
});
|
|
626
507
|
const value = _react.useMemo.call(void 0,
|
|
627
508
|
() => ({
|
|
628
509
|
isLoading,
|
|
@@ -635,42 +516,23 @@ var AuthProvider = ({
|
|
|
635
516
|
}),
|
|
636
517
|
[isLoading, error, signOutMutation, isAuthenticated, signIn]
|
|
637
518
|
);
|
|
638
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AuthContext.Provider, { value, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
656
|
-
CivicAuthIframeContainer,
|
|
657
|
-
{
|
|
658
|
-
onClose: () => setShowIFrame(false)
|
|
659
|
-
}
|
|
660
|
-
)
|
|
661
|
-
}
|
|
662
|
-
),
|
|
663
|
-
modalIframe && (isInIframe || isRedirecting || isLoading && !serverTokenExchange) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BlockDisplay, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LoadingIcon, {}) }),
|
|
664
|
-
(tokenExchangeError || error) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BlockDisplay, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
|
|
665
|
-
"Error: ",
|
|
666
|
-
(tokenExchangeError || error).message
|
|
667
|
-
] }) }),
|
|
668
|
-
children
|
|
669
|
-
] }) })
|
|
670
|
-
}
|
|
671
|
-
)
|
|
672
|
-
}
|
|
673
|
-
) });
|
|
519
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AuthContext.Provider, { value, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SessionProvider, { session, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TokenProvider, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, UserProvider, { userInfoService, children: [
|
|
520
|
+
!isInIframe && iframeUrl && !(session == null ? void 0 : session.authenticated) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
521
|
+
CivicAuthIframeModal,
|
|
522
|
+
{
|
|
523
|
+
iframeRef,
|
|
524
|
+
authUrl: iframeUrl,
|
|
525
|
+
redirectUri: redirectUrl,
|
|
526
|
+
setAuthResponseUrl,
|
|
527
|
+
onClose: () => setIframeUrl(null)
|
|
528
|
+
}
|
|
529
|
+
),
|
|
530
|
+
(tokenExchangeError || isLoading || error || isInIframe && !(tokenExchangeError || error)) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "absolute left-0 top-0 z-50 flex h-screen w-screen items-center justify-center bg-white", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "absolute inset-0 flex items-center justify-center bg-white", children: tokenExchangeError || error ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
|
|
531
|
+
"Error: ",
|
|
532
|
+
(tokenExchangeError || error).message
|
|
533
|
+
] }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LoadingIcon, {}) }) }),
|
|
534
|
+
children
|
|
535
|
+
] }) }) }) });
|
|
674
536
|
};
|
|
675
537
|
|
|
676
538
|
// src/shared/CivicAuthProvider.tsx
|
|
@@ -680,41 +542,29 @@ require('@civic/auth/styles.css');
|
|
|
680
542
|
var queryClient = new (0, _reactquery.QueryClient)();
|
|
681
543
|
var CivicAuthProvider = (_a) => {
|
|
682
544
|
var _b = _a, { children } = _b, props = _chunkCRTRMMJ7js.__objRest.call(void 0, _b, ["children"]);
|
|
683
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactquery.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
684
|
-
AuthProvider,
|
|
685
|
-
_chunkCRTRMMJ7js.__spreadProps.call(void 0, _chunkCRTRMMJ7js.__spreadValues.call(void 0, {}, props), {
|
|
686
|
-
pkceConsumer: new (0, _chunkRF23Q4V6js.BrowserPublicClientPKCEProducer)(),
|
|
687
|
-
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, UserProvider, { storage: new (0, _chunkRF23Q4V6js.LocalStorageAdapter)(), children })
|
|
688
|
-
})
|
|
689
|
-
) });
|
|
545
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactquery.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AuthProvider, _chunkCRTRMMJ7js.__spreadProps.call(void 0, _chunkCRTRMMJ7js.__spreadValues.call(void 0, {}, props), { children })) });
|
|
690
546
|
};
|
|
691
547
|
|
|
692
548
|
// src/react/providers/NextAuthProvider.tsx
|
|
693
549
|
|
|
694
550
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
// src/react/hooks/useTokenCookie.ts
|
|
551
|
+
// src/react/hooks/useUserCookie.ts
|
|
698
552
|
|
|
699
553
|
var _navigationjs = require('next/navigation.js');
|
|
700
554
|
|
|
701
555
|
|
|
702
556
|
// src/lib/cookies.ts
|
|
703
|
-
var
|
|
704
|
-
key,
|
|
705
|
-
window: window2,
|
|
706
|
-
parseJson = false
|
|
707
|
-
}) => {
|
|
557
|
+
var getCookieValue = (key, window2) => {
|
|
708
558
|
const cookie = window2.document.cookie;
|
|
709
559
|
if (!cookie) return null;
|
|
710
560
|
const cookies = cookie.split(";");
|
|
711
561
|
for (const c of cookies) {
|
|
712
562
|
const [name, value] = c.trim().split("=");
|
|
713
|
-
if (
|
|
563
|
+
if (name === key) {
|
|
714
564
|
try {
|
|
715
|
-
|
|
716
|
-
return parseJson === true ? JSON.parse(decodeURIComponentValue) : decodeURIComponentValue;
|
|
565
|
+
return JSON.parse(decodeURIComponent(value));
|
|
717
566
|
} catch (e) {
|
|
567
|
+
console.log("Error parsing cookie value", e);
|
|
718
568
|
return value;
|
|
719
569
|
}
|
|
720
570
|
}
|
|
@@ -722,27 +572,24 @@ var getWindowCookieValue = ({
|
|
|
722
572
|
return null;
|
|
723
573
|
};
|
|
724
574
|
|
|
725
|
-
// src/react/hooks/
|
|
726
|
-
var
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
window: globalThis.window,
|
|
730
|
-
parseJson: false
|
|
731
|
-
});
|
|
575
|
+
// src/react/hooks/useUserCookie.ts
|
|
576
|
+
var getUserFromCookie = () => {
|
|
577
|
+
const userCookie = getCookieValue("user", globalThis.window);
|
|
578
|
+
return userCookie;
|
|
732
579
|
};
|
|
733
|
-
var
|
|
580
|
+
var useUserCookie = () => {
|
|
734
581
|
const hasRunRef = _react.useRef.call(void 0, false);
|
|
735
582
|
const router = _navigationjs.useRouter.call(void 0, );
|
|
736
|
-
const { data:
|
|
737
|
-
queryKey: ["
|
|
738
|
-
queryFn: () =>
|
|
583
|
+
const { data: user } = _reactquery.useQuery.call(void 0, {
|
|
584
|
+
queryKey: ["user"],
|
|
585
|
+
queryFn: () => getUserFromCookie(),
|
|
739
586
|
refetchInterval: 2e3,
|
|
740
587
|
refetchIntervalInBackground: true,
|
|
741
588
|
enabled: !hasRunRef.current,
|
|
742
589
|
refetchOnWindowFocus: true
|
|
743
590
|
});
|
|
744
591
|
_react.useEffect.call(void 0, () => {
|
|
745
|
-
if (
|
|
592
|
+
if (user) {
|
|
746
593
|
if (!hasRunRef.current) {
|
|
747
594
|
hasRunRef.current = true;
|
|
748
595
|
router.refresh();
|
|
@@ -750,59 +597,51 @@ var useTokenCookie = (tokenName) => {
|
|
|
750
597
|
} else {
|
|
751
598
|
hasRunRef.current = false;
|
|
752
599
|
}
|
|
753
|
-
}, [
|
|
754
|
-
return
|
|
600
|
+
}, [user, router]);
|
|
601
|
+
return user;
|
|
755
602
|
};
|
|
756
603
|
|
|
757
604
|
// src/react/providers/NextAuthProvider.tsx
|
|
758
605
|
|
|
606
|
+
|
|
759
607
|
var queryClient2 = new (0, _reactquery.QueryClient)();
|
|
608
|
+
var defaultUserContext = { user: null };
|
|
609
|
+
var UserContext2 = _react.createContext.call(void 0, defaultUserContext);
|
|
760
610
|
var CivicNextAuthProvider = (_a) => {
|
|
761
611
|
var _b = _a, {
|
|
762
612
|
children
|
|
763
613
|
} = _b, props = _chunkCRTRMMJ7js.__objRest.call(void 0, _b, [
|
|
764
614
|
"children"
|
|
765
615
|
]);
|
|
616
|
+
const user = useUserCookie();
|
|
766
617
|
const [redirectUrl, setRedirectUrl] = _react.useState.call(void 0, "");
|
|
767
|
-
const { clientId, oauthServer, callbackUrl, challengeUrl
|
|
618
|
+
const { clientId, oauthServer, callbackUrl, challengeUrl } = _chunkKS7ERXGZjs.resolveAuthConfig.call(void 0, );
|
|
768
619
|
_react.useEffect.call(void 0, () => {
|
|
769
620
|
if (typeof globalThis.window !== "undefined") {
|
|
770
621
|
const currentUrl = globalThis.window.location.href;
|
|
771
|
-
setRedirectUrl(
|
|
622
|
+
setRedirectUrl(new URL(callbackUrl, currentUrl).toString());
|
|
772
623
|
}
|
|
773
624
|
}, [callbackUrl]);
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
(_a2 = props.onSignOut) == null ? void 0 : _a2.call(props);
|
|
783
|
-
window.location.href = logoutUrl;
|
|
784
|
-
return;
|
|
785
|
-
});
|
|
625
|
+
const authService = _react.useMemo.call(void 0, () => {
|
|
626
|
+
if (redirectUrl && clientId && oauthServer) {
|
|
627
|
+
return new (0, _chunkKS7ERXGZjs.AuthSessionServiceImpl)(clientId, redirectUrl, oauthServer, {
|
|
628
|
+
challenge: challengeUrl
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
return void 0;
|
|
632
|
+
}, [redirectUrl, clientId, oauthServer, challengeUrl]);
|
|
786
633
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactquery.QueryClientProvider, { client: queryClient2, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
787
634
|
AuthProvider,
|
|
788
635
|
_chunkCRTRMMJ7js.__spreadProps.call(void 0, _chunkCRTRMMJ7js.__spreadValues.call(void 0, {}, props), {
|
|
789
|
-
redirectUrl,
|
|
790
636
|
config: { oauthServer },
|
|
791
637
|
clientId,
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
795
|
-
UserProvider,
|
|
796
|
-
{
|
|
797
|
-
storage: new (0, _chunkSEKF2WZXjs.NextjsClientStorage)(),
|
|
798
|
-
user: combinedUser,
|
|
799
|
-
signOut,
|
|
800
|
-
children
|
|
801
|
-
}
|
|
802
|
-
)
|
|
638
|
+
authServiceImpl: authService,
|
|
639
|
+
serverSideTokenExchange: true,
|
|
640
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, UserContext2.Provider, { value: user, children })
|
|
803
641
|
})
|
|
804
642
|
) });
|
|
805
643
|
};
|
|
644
|
+
var useNextUser = () => _react.useContext.call(void 0, UserContext2);
|
|
806
645
|
|
|
807
646
|
// src/react/hooks/useUser.tsx
|
|
808
647
|
var useUser = () => {
|
|
@@ -813,62 +652,6 @@ var useUser = () => {
|
|
|
813
652
|
return context;
|
|
814
653
|
};
|
|
815
654
|
|
|
816
|
-
// src/react/hooks/useUserCookie.ts
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
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 = _react.useRef.call(void 0, false);
|
|
830
|
-
const router = _navigationjs.useRouter.call(void 0, );
|
|
831
|
-
const { data: user } = _reactquery.useQuery.call(void 0, {
|
|
832
|
-
queryKey: ["user"],
|
|
833
|
-
queryFn: () => getUserFromCookie(),
|
|
834
|
-
refetchInterval: 2e3,
|
|
835
|
-
refetchIntervalInBackground: true,
|
|
836
|
-
enabled: !hasRunRef.current,
|
|
837
|
-
refetchOnWindowFocus: true
|
|
838
|
-
});
|
|
839
|
-
_react.useEffect.call(void 0, () => {
|
|
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
|
-
|
|
854
|
-
var useConfig = () => {
|
|
855
|
-
const context = _react.useContext.call(void 0, 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
|
-
|
|
864
|
-
var useIframe = () => {
|
|
865
|
-
const context = _react.useContext.call(void 0, IframeContext);
|
|
866
|
-
if (!context) {
|
|
867
|
-
throw new Error("useIframe must be used within an IframeProvider");
|
|
868
|
-
}
|
|
869
|
-
return context;
|
|
870
|
-
};
|
|
871
|
-
|
|
872
655
|
// src/react/components/UserButton.tsx
|
|
873
656
|
|
|
874
657
|
|
|
@@ -909,7 +692,8 @@ var UserButton = ({
|
|
|
909
692
|
className
|
|
910
693
|
}) => {
|
|
911
694
|
const [isOpen, setIsOpen] = _react.useState.call(void 0, false);
|
|
912
|
-
const {
|
|
695
|
+
const { signIn, isAuthenticated, signOut } = useAuth();
|
|
696
|
+
const { user } = useUser();
|
|
913
697
|
const handleClickOutside = _react.useCallback.call(void 0, (event) => {
|
|
914
698
|
const target = event.target;
|
|
915
699
|
if (!target.closest("#civic-dropdown-container")) {
|
|
@@ -917,7 +701,7 @@ var UserButton = ({
|
|
|
917
701
|
}
|
|
918
702
|
}, []);
|
|
919
703
|
const handleSignOut = _react.useCallback.call(void 0, () => _chunkCRTRMMJ7js.__async.call(void 0, void 0, null, function* () {
|
|
920
|
-
signOut();
|
|
704
|
+
yield signOut();
|
|
921
705
|
setIsOpen(false);
|
|
922
706
|
}), [signOut]);
|
|
923
707
|
const handleSignIn = _react.useCallback.call(void 0, () => _chunkCRTRMMJ7js.__async.call(void 0, void 0, null, function* () {
|
|
@@ -939,21 +723,21 @@ var UserButton = ({
|
|
|
939
723
|
window.removeEventListener("keydown", handleEscape);
|
|
940
724
|
};
|
|
941
725
|
}, [handleClickOutside, handleEscape, isOpen]);
|
|
942
|
-
if (
|
|
943
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "
|
|
726
|
+
if (isAuthenticated) {
|
|
727
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "relative", id: "civic-dropdown-container", children: [
|
|
944
728
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
945
729
|
"button",
|
|
946
730
|
{
|
|
947
|
-
className:
|
|
948
|
-
"
|
|
731
|
+
className: _chunkNINRO7GSjs.cn.call(void 0,
|
|
732
|
+
"flex w-full items-center justify-between gap-2 rounded-full border border-neutral-500 px-3 py-2 text-neutral-500 transition-colors hover:bg-neutral-200 hover:bg-opacity-50",
|
|
949
733
|
className
|
|
950
734
|
),
|
|
951
735
|
onClick: () => setIsOpen((isOpen2) => !isOpen2),
|
|
952
736
|
children: [
|
|
953
|
-
(user == null ? void 0 : user.picture) ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "
|
|
737
|
+
(user == null ? void 0 : user.picture) ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "relative flex h-10 w-10 shrink-0 gap-2 overflow-hidden rounded-full", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
954
738
|
"img",
|
|
955
739
|
{
|
|
956
|
-
className: "
|
|
740
|
+
className: "h-full w-full object-cover",
|
|
957
741
|
src: user.picture,
|
|
958
742
|
alt: (user == null ? void 0 : user.name) || (user == null ? void 0 : user.email)
|
|
959
743
|
}
|
|
@@ -966,11 +750,11 @@ var UserButton = ({
|
|
|
966
750
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
967
751
|
"div",
|
|
968
752
|
{
|
|
969
|
-
className: isOpen ? "
|
|
753
|
+
className: isOpen ? "absolute right-0 mt-2 w-full rounded-lg bg-white py-2 text-neutral-500 shadow-xl" : "hidden",
|
|
970
754
|
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "ul", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "li", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
971
755
|
"button",
|
|
972
756
|
{
|
|
973
|
-
className: "
|
|
757
|
+
className: "block w-full px-4 py-2 transition-colors hover:bg-neutral-200 hover:bg-opacity-50",
|
|
974
758
|
onClick: handleSignOut,
|
|
975
759
|
children: "Logout"
|
|
976
760
|
}
|
|
@@ -982,9 +766,8 @@ var UserButton = ({
|
|
|
982
766
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
983
767
|
"button",
|
|
984
768
|
{
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
"cac-rounded-full cac-border cac-border-neutral-500 cac-px-3 cac-py-2 cac-transition-colors hover:cac-bg-neutral-200 hover:cac-bg-opacity-50",
|
|
769
|
+
className: _chunkNINRO7GSjs.cn.call(void 0,
|
|
770
|
+
"rounded-full border border-neutral-500 px-3 py-2 transition-colors hover:bg-neutral-200 hover:bg-opacity-50",
|
|
988
771
|
className
|
|
989
772
|
),
|
|
990
773
|
onClick: handleSignIn,
|
|
@@ -999,13 +782,12 @@ var SignInButton = ({
|
|
|
999
782
|
displayMode,
|
|
1000
783
|
className
|
|
1001
784
|
}) => {
|
|
1002
|
-
const { signIn } =
|
|
785
|
+
const { signIn } = useAuth();
|
|
1003
786
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1004
787
|
"button",
|
|
1005
788
|
{
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
"cac-rounded-full cac-border cac-border-neutral-500 cac-px-3 cac-py-2 cac-transition-colors hover:cac-bg-neutral-200 hover:cac-bg-opacity-50",
|
|
789
|
+
className: _chunkNINRO7GSjs.cn.call(void 0,
|
|
790
|
+
"rounded-full border border-neutral-500 px-3 py-2 transition-colors hover:bg-neutral-200 hover:bg-opacity-50",
|
|
1009
791
|
className
|
|
1010
792
|
),
|
|
1011
793
|
onClick: () => signIn(displayMode),
|
|
@@ -1017,12 +799,12 @@ var SignInButton = ({
|
|
|
1017
799
|
// src/react/components/SignOutButton.tsx
|
|
1018
800
|
|
|
1019
801
|
var SignOutButton = ({ className }) => {
|
|
1020
|
-
const { signOut } =
|
|
802
|
+
const { signOut } = useAuth();
|
|
1021
803
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1022
804
|
"button",
|
|
1023
805
|
{
|
|
1024
|
-
className:
|
|
1025
|
-
"
|
|
806
|
+
className: _chunkNINRO7GSjs.cn.call(void 0,
|
|
807
|
+
"rounded-full border border-neutral-500 px-3 py-2 transition-colors hover:bg-neutral-200 hover:bg-opacity-50",
|
|
1026
808
|
className
|
|
1027
809
|
),
|
|
1028
810
|
onClick: () => signOut(),
|
|
@@ -1034,7 +816,7 @@ var SignOutButton = ({ className }) => {
|
|
|
1034
816
|
// src/react/components/NextLogOut.tsx
|
|
1035
817
|
|
|
1036
818
|
var NextLogOut = ({ children }) => {
|
|
1037
|
-
const config =
|
|
819
|
+
const config = _chunkKS7ERXGZjs.resolveAuthConfig.call(void 0, );
|
|
1038
820
|
const logoutUrl = `${config.logoutUrl}`;
|
|
1039
821
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "a", { href: logoutUrl, children });
|
|
1040
822
|
};
|
|
@@ -1051,8 +833,5 @@ var NextLogOut = ({ children }) => {
|
|
|
1051
833
|
|
|
1052
834
|
|
|
1053
835
|
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
exports.CivicAuthIframeContainer = CivicAuthIframeContainer; exports.CivicAuthProvider = CivicAuthProvider; exports.CivicNextAuthProvider = CivicNextAuthProvider; exports.NextLogOut = NextLogOut; exports.SignInButton = SignInButton; exports.SignOutButton = SignOutButton; exports.UserButton = UserButton; exports.useAuth = useAuth; exports.useConfig = useConfig; exports.useIframe = useIframe; exports.useSession = useSession; exports.useToken = useToken; exports.useTokenCookie = useTokenCookie; exports.useUser = useUser; exports.useUserCookie = useUserCookie;
|
|
836
|
+
exports.CivicAuthProvider = CivicAuthProvider; exports.CivicNextAuthProvider = CivicNextAuthProvider; exports.NextLogOut = NextLogOut; exports.SignInButton = SignInButton; exports.SignOutButton = SignOutButton; exports.UserButton = UserButton; exports.useAuth = useAuth; exports.useNextUser = useNextUser; exports.useSession = useSession; exports.useToken = useToken; exports.useUser = useUser; exports.useUserCookie = useUserCookie;
|
|
1058
837
|
//# sourceMappingURL=react.js.map
|