dauth-context-react 2.2.0 → 2.4.0

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/index.mjs ADDED
@@ -0,0 +1,715 @@
1
+ // src/index.tsx
2
+ import {
3
+ useReducer,
4
+ useMemo,
5
+ useEffect,
6
+ useCallback,
7
+ createContext,
8
+ useContext,
9
+ useRef
10
+ } from "react";
11
+
12
+ // src/initialDauthState.ts
13
+ var initialDauthState = {
14
+ user: {
15
+ language: (typeof window !== "undefined" ? window.document.documentElement.getAttribute("lang") : null) || "es"
16
+ },
17
+ domain: {},
18
+ isLoading: true,
19
+ isAuthenticated: false,
20
+ loginWithRedirect: () => {
21
+ },
22
+ logout: () => {
23
+ },
24
+ getAccessToken: () => Promise.resolve(""),
25
+ updateUser: () => Promise.resolve(false),
26
+ updateUserWithRedirect: () => {
27
+ },
28
+ // Send email verification
29
+ sendEmailVerificationStatus: {
30
+ status: {
31
+ type: "info",
32
+ message: "Sending email verification..."
33
+ },
34
+ isLoading: false
35
+ },
36
+ sendEmailVerification: () => Promise.resolve(false),
37
+ deleteAccount: () => Promise.resolve(false)
38
+ };
39
+ var initialDauthState_default = initialDauthState;
40
+
41
+ // src/reducer/dauth.types.ts
42
+ var LOGIN = "LOGIN";
43
+ var SET_IS_LOADING = "SET_IS_LOADING";
44
+ var UPDATE_USER = "UPDATE_USER";
45
+ var SET_SEND_EMAIL_VERIFICATION_IS_LOADING = "SET_SEND_EMAIL_VERIFICATION_IS_LOADING";
46
+ var SET_SEND_EMAIL_VERIFICATION_STATUS = "SET_SEND_EMAIL_VERIFICATION_STATUS";
47
+
48
+ // src/reducer/dauth.reducer.ts
49
+ function userReducer(state, action) {
50
+ const { type, payload } = action;
51
+ switch (type) {
52
+ case LOGIN: {
53
+ const login = {
54
+ ...state,
55
+ user: payload.user,
56
+ domain: payload.domain,
57
+ isAuthenticated: payload.isAuthenticated
58
+ };
59
+ return login;
60
+ }
61
+ case SET_IS_LOADING: {
62
+ const isLoading = {
63
+ ...state,
64
+ isLoading: payload.isLoading
65
+ };
66
+ return isLoading;
67
+ }
68
+ case UPDATE_USER: {
69
+ const updateUser = {
70
+ ...state,
71
+ user: {
72
+ ...state.user,
73
+ ...payload
74
+ }
75
+ };
76
+ return updateUser;
77
+ }
78
+ case SET_SEND_EMAIL_VERIFICATION_STATUS: {
79
+ const setSendEmailVerificationStatus = {
80
+ ...state,
81
+ sendEmailVerificationStatus: {
82
+ ...state.sendEmailVerificationStatus,
83
+ status: {
84
+ type: payload.type,
85
+ message: payload.message
86
+ }
87
+ }
88
+ };
89
+ return setSendEmailVerificationStatus;
90
+ }
91
+ case SET_SEND_EMAIL_VERIFICATION_IS_LOADING: {
92
+ const setSendEmailVerificationIsLoading = {
93
+ ...state,
94
+ sendEmailVerificationStatus: {
95
+ ...state.sendEmailVerificationStatus,
96
+ isLoading: payload
97
+ }
98
+ };
99
+ return setSendEmailVerificationIsLoading;
100
+ }
101
+ default:
102
+ return state;
103
+ }
104
+ }
105
+
106
+ // src/api/utils/config.ts
107
+ var apiVersion = "v1";
108
+ var serverDomain = "dauth.ovh";
109
+ function checkIsLocalhost() {
110
+ if (typeof window === "undefined") return false;
111
+ const hostname = window.location.hostname;
112
+ return Boolean(
113
+ hostname === "localhost" || hostname === "[::1]" || hostname.match(
114
+ /(192)\.(168)\.(1)\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm
115
+ ) || hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
116
+ );
117
+ }
118
+ function getServerBasePath() {
119
+ const isLocalhost = checkIsLocalhost();
120
+ const serverPort = 4012;
121
+ const serverLocalUrl = `${window.location.protocol}//${window.location.hostname}:${serverPort}/api/${apiVersion}`;
122
+ const serverProdUrl = `https://${serverDomain}/api/${apiVersion}`;
123
+ return isLocalhost ? serverLocalUrl : serverProdUrl;
124
+ }
125
+ function getClientBasePath() {
126
+ const isLocalhost = checkIsLocalhost();
127
+ const clientPort = 5185;
128
+ const clientLocalUrl = `${window.location.protocol}//${window.location.hostname}:${clientPort}`;
129
+ const clientProdUrl = `https://${serverDomain}`;
130
+ return isLocalhost ? clientLocalUrl : clientProdUrl;
131
+ }
132
+
133
+ // src/api/dauth.api.ts
134
+ var getUserAPI = async (domainName, token) => {
135
+ const params = {
136
+ method: "GET",
137
+ headers: {
138
+ Authorization: token,
139
+ "Content-Type": "application/json"
140
+ }
141
+ };
142
+ const response = await fetch(
143
+ `${getServerBasePath()}/app/${domainName}/user`,
144
+ params
145
+ );
146
+ const data = await response.json();
147
+ return { response, data };
148
+ };
149
+ var updateUserAPI = async (domainName, user, token) => {
150
+ const params = {
151
+ method: "PATCH",
152
+ headers: {
153
+ Authorization: token,
154
+ "Content-Type": "application/json"
155
+ },
156
+ body: JSON.stringify(user)
157
+ };
158
+ const response = await fetch(
159
+ `${getServerBasePath()}/app/${domainName}/user`,
160
+ params
161
+ );
162
+ const data = await response.json();
163
+ return { response, data };
164
+ };
165
+ var sendEmailVerificationAPI = async (domainName, token) => {
166
+ const params = {
167
+ method: "GET",
168
+ headers: {
169
+ Authorization: token,
170
+ "Content-Type": "application/json"
171
+ }
172
+ };
173
+ const response = await fetch(
174
+ `${getServerBasePath()}/app/${domainName}/resend-email-verification`,
175
+ params
176
+ );
177
+ const data = await response.json();
178
+ return { response, data };
179
+ };
180
+ var refreshTokenAPI = async (domainName, refreshToken) => {
181
+ const params = {
182
+ method: "POST",
183
+ headers: { "Content-Type": "application/json" },
184
+ body: JSON.stringify({ refreshToken })
185
+ };
186
+ const response = await fetch(
187
+ `${getServerBasePath()}/app/${domainName}/refresh-token`,
188
+ params
189
+ );
190
+ const data = await response.json();
191
+ return { response, data };
192
+ };
193
+ var deleteAccountAPI = async (domainName, token) => {
194
+ const params = {
195
+ method: "DELETE",
196
+ headers: {
197
+ Authorization: token,
198
+ "Content-Type": "application/json"
199
+ }
200
+ };
201
+ const response = await fetch(
202
+ `${getServerBasePath()}/app/${domainName}/user`,
203
+ params
204
+ );
205
+ const data = await response.json();
206
+ return { response, data };
207
+ };
208
+ var logoutAPI = async (domainName, refreshToken) => {
209
+ const params = {
210
+ method: "POST",
211
+ headers: { "Content-Type": "application/json" },
212
+ body: JSON.stringify({ refreshToken })
213
+ };
214
+ const response = await fetch(
215
+ `${getServerBasePath()}/app/${domainName}/logout`,
216
+ params
217
+ );
218
+ return { response };
219
+ };
220
+
221
+ // src/reducer/dauth.actions.ts
222
+ async function setDauthStateAction({
223
+ dispatch,
224
+ token,
225
+ refreshToken,
226
+ domainName,
227
+ storageKeys,
228
+ onError
229
+ }) {
230
+ dispatch({ type: SET_IS_LOADING, payload: { isLoading: true } });
231
+ try {
232
+ const getUserFetch = await getUserAPI(domainName, token);
233
+ if (getUserFetch.response.status === 200) {
234
+ dispatch({
235
+ type: LOGIN,
236
+ payload: {
237
+ user: getUserFetch.data.user,
238
+ domain: getUserFetch.data.domain,
239
+ isAuthenticated: true
240
+ }
241
+ });
242
+ window.history.replaceState({}, document.title, window.location.pathname);
243
+ localStorage.setItem(storageKeys.accessToken, token);
244
+ localStorage.setItem(storageKeys.refreshToken, refreshToken);
245
+ return;
246
+ } else {
247
+ return resetUser(dispatch, storageKeys);
248
+ }
249
+ } catch (error) {
250
+ onError(error instanceof Error ? error : new Error(String(error)));
251
+ return resetUser(dispatch, storageKeys);
252
+ } finally {
253
+ dispatch({
254
+ type: SET_IS_LOADING,
255
+ payload: { isLoading: false }
256
+ });
257
+ }
258
+ }
259
+ async function setAutoLoginAction({
260
+ dispatch,
261
+ domainName,
262
+ storageKeys,
263
+ onError
264
+ }) {
265
+ dispatch({ type: SET_IS_LOADING, payload: { isLoading: true } });
266
+ const storedRefreshToken = localStorage.getItem(storageKeys.refreshToken);
267
+ if (!storedRefreshToken) {
268
+ dispatch({
269
+ type: SET_IS_LOADING,
270
+ payload: { isLoading: false }
271
+ });
272
+ return resetUser(dispatch, storageKeys);
273
+ }
274
+ try {
275
+ const refreshResult = await refreshTokenAPI(domainName, storedRefreshToken);
276
+ if (refreshResult.response.status === 200) {
277
+ const newAccessToken = refreshResult.data.accessToken;
278
+ const newRefreshToken = refreshResult.data.refreshToken;
279
+ localStorage.setItem(storageKeys.accessToken, newAccessToken);
280
+ localStorage.setItem(storageKeys.refreshToken, newRefreshToken);
281
+ const getUserFetch = await getUserAPI(domainName, newAccessToken);
282
+ if (getUserFetch.response.status === 200) {
283
+ dispatch({
284
+ type: LOGIN,
285
+ payload: {
286
+ user: getUserFetch.data.user,
287
+ domain: getUserFetch.data.domain,
288
+ isAuthenticated: true
289
+ }
290
+ });
291
+ return;
292
+ }
293
+ }
294
+ resetUser(dispatch, storageKeys);
295
+ } catch (error) {
296
+ onError(error instanceof Error ? error : new Error(String(error)));
297
+ resetUser(dispatch, storageKeys);
298
+ } finally {
299
+ dispatch({
300
+ type: SET_IS_LOADING,
301
+ payload: { isLoading: false }
302
+ });
303
+ }
304
+ }
305
+ async function setLogoutAction({
306
+ dispatch,
307
+ domainName,
308
+ storageKeys
309
+ }) {
310
+ const storedRefreshToken = localStorage.getItem(storageKeys.refreshToken);
311
+ if (storedRefreshToken && domainName) {
312
+ try {
313
+ await logoutAPI(domainName, storedRefreshToken);
314
+ } catch (_) {
315
+ }
316
+ }
317
+ dispatch({ type: SET_IS_LOADING, payload: { isLoading: true } });
318
+ dispatch({
319
+ type: LOGIN,
320
+ payload: {
321
+ user: {
322
+ language: window.document.documentElement.getAttribute("lang") || "es"
323
+ },
324
+ domain: {},
325
+ isAuthenticated: false
326
+ }
327
+ });
328
+ localStorage.removeItem(storageKeys.accessToken);
329
+ localStorage.removeItem(storageKeys.refreshToken);
330
+ return dispatch({
331
+ type: SET_IS_LOADING,
332
+ payload: { isLoading: false }
333
+ });
334
+ }
335
+ async function refreshSessionAction({
336
+ dispatch,
337
+ domainName,
338
+ storageKeys,
339
+ onError
340
+ }) {
341
+ const storedRefreshToken = localStorage.getItem(storageKeys.refreshToken);
342
+ if (!storedRefreshToken) {
343
+ return resetUser(dispatch, storageKeys);
344
+ }
345
+ try {
346
+ const refreshResult = await refreshTokenAPI(domainName, storedRefreshToken);
347
+ if (refreshResult.response.status === 200) {
348
+ localStorage.setItem(
349
+ storageKeys.accessToken,
350
+ refreshResult.data.accessToken
351
+ );
352
+ localStorage.setItem(
353
+ storageKeys.refreshToken,
354
+ refreshResult.data.refreshToken
355
+ );
356
+ return;
357
+ }
358
+ resetUser(dispatch, storageKeys);
359
+ } catch (error) {
360
+ onError(error instanceof Error ? error : new Error(String(error)));
361
+ resetUser(dispatch, storageKeys);
362
+ }
363
+ }
364
+ async function setUpdateUserAction({
365
+ dispatch,
366
+ domainName,
367
+ user,
368
+ token,
369
+ onError
370
+ }) {
371
+ if (user.language) {
372
+ window.document.documentElement.setAttribute("lang", user.language);
373
+ }
374
+ if (!token) {
375
+ dispatch({
376
+ type: UPDATE_USER,
377
+ payload: user
378
+ });
379
+ return false;
380
+ }
381
+ try {
382
+ const getUserFetch = await updateUserAPI(domainName, user, token);
383
+ if (getUserFetch.response.status === 200) {
384
+ dispatch({
385
+ type: UPDATE_USER,
386
+ payload: getUserFetch.data.user
387
+ });
388
+ return true;
389
+ } else {
390
+ onError(new Error("Update user error: " + getUserFetch.data.message));
391
+ return false;
392
+ }
393
+ } catch (error) {
394
+ onError(
395
+ error instanceof Error ? error : new Error("Update user error")
396
+ );
397
+ return false;
398
+ }
399
+ }
400
+ async function sendEmailVerificationAction({
401
+ dispatch,
402
+ domainName,
403
+ token
404
+ }) {
405
+ dispatch({
406
+ type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
407
+ payload: true
408
+ });
409
+ dispatch({
410
+ type: SET_SEND_EMAIL_VERIFICATION_STATUS,
411
+ payload: { type: "info", message: "Sending email verification..." }
412
+ });
413
+ try {
414
+ const sendEmailFetch = await sendEmailVerificationAPI(domainName, token);
415
+ if (sendEmailFetch.response.status === 200) {
416
+ dispatch({
417
+ type: SET_SEND_EMAIL_VERIFICATION_STATUS,
418
+ payload: { type: "success", message: sendEmailFetch.data.message }
419
+ });
420
+ dispatch({
421
+ type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
422
+ payload: false
423
+ });
424
+ return true;
425
+ } else {
426
+ dispatch({
427
+ type: SET_SEND_EMAIL_VERIFICATION_STATUS,
428
+ payload: { type: "error", message: sendEmailFetch.data.message }
429
+ });
430
+ dispatch({
431
+ type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
432
+ payload: false
433
+ });
434
+ return false;
435
+ }
436
+ } catch (_) {
437
+ dispatch({
438
+ type: SET_SEND_EMAIL_VERIFICATION_STATUS,
439
+ payload: {
440
+ type: "error",
441
+ message: "Send email verification fetch error"
442
+ }
443
+ });
444
+ dispatch({
445
+ type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
446
+ payload: false
447
+ });
448
+ return false;
449
+ }
450
+ }
451
+ async function getAccessTokenAction({
452
+ dispatch,
453
+ domainName,
454
+ storageKeys,
455
+ onError
456
+ }) {
457
+ const token_ls = localStorage.getItem(storageKeys.accessToken);
458
+ if (!token_ls) return "token-not-found";
459
+ try {
460
+ const payloadB64 = token_ls.split(".")[1];
461
+ if (payloadB64) {
462
+ const payload = JSON.parse(atob(payloadB64));
463
+ const expiresIn = (payload.exp || 0) * 1e3 - Date.now();
464
+ if (expiresIn < 5 * 60 * 1e3) {
465
+ await refreshSessionAction({
466
+ dispatch,
467
+ domainName,
468
+ storageKeys,
469
+ onError
470
+ });
471
+ const refreshedToken = localStorage.getItem(storageKeys.accessToken);
472
+ return refreshedToken || "token-not-found";
473
+ }
474
+ }
475
+ } catch (_) {
476
+ }
477
+ return token_ls;
478
+ }
479
+ async function deleteAccountAction({
480
+ dispatch,
481
+ domainName,
482
+ storageKeys,
483
+ onError,
484
+ token
485
+ }) {
486
+ try {
487
+ const result = await deleteAccountAPI(domainName, token);
488
+ if (result.response.status === 200) {
489
+ resetUser(dispatch, storageKeys);
490
+ return true;
491
+ }
492
+ return false;
493
+ } catch (error) {
494
+ onError(
495
+ error instanceof Error ? error : new Error("Delete account error")
496
+ );
497
+ return false;
498
+ }
499
+ }
500
+ var resetUser = (dispatch, storageKeys) => {
501
+ localStorage.removeItem(storageKeys.accessToken);
502
+ localStorage.removeItem(storageKeys.refreshToken);
503
+ return dispatch({
504
+ type: LOGIN,
505
+ payload: {
506
+ user: {},
507
+ domain: {},
508
+ isAuthenticated: false
509
+ }
510
+ });
511
+ };
512
+
513
+ // src/constants.ts
514
+ var TOKEN_LS = "dauth_state";
515
+ var REFRESH_TOKEN_LS = "dauth_refresh_token";
516
+
517
+ // src/api/utils/routes.ts
518
+ var routes = {
519
+ signin: "signin",
520
+ updateUser: "update-user"
521
+ };
522
+
523
+ // src/index.tsx
524
+ import { jsx } from "react/jsx-runtime";
525
+ var defaultOnError = (error) => console.error(error);
526
+ var DauthProvider = (props) => {
527
+ const { domainName, children, storageKey, onError, env } = props;
528
+ const [dauthState, dispatch] = useReducer(userReducer, initialDauthState_default);
529
+ const refreshTimerRef = useRef(null);
530
+ const storageKeys = useMemo(
531
+ () => ({
532
+ accessToken: storageKey?.accessToken ?? TOKEN_LS,
533
+ refreshToken: storageKey?.refreshToken ?? REFRESH_TOKEN_LS
534
+ }),
535
+ [storageKey?.accessToken, storageKey?.refreshToken]
536
+ );
537
+ const handleError = useCallback(
538
+ (error) => (onError ?? defaultOnError)(error),
539
+ [onError]
540
+ );
541
+ const ctx = useMemo(
542
+ () => ({ dispatch, domainName, storageKeys, onError: handleError }),
543
+ [domainName, storageKeys, handleError]
544
+ );
545
+ const scheduleRefresh = useCallback(() => {
546
+ if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
547
+ const token = localStorage.getItem(storageKeys.accessToken);
548
+ if (!token) return;
549
+ try {
550
+ const payloadB64 = token.split(".")[1];
551
+ if (!payloadB64) return;
552
+ const payload = JSON.parse(atob(payloadB64));
553
+ const expiresIn = (payload.exp || 0) * 1e3 - Date.now();
554
+ const refreshIn = Math.max(expiresIn - 5 * 60 * 1e3, 1e4);
555
+ refreshTimerRef.current = setTimeout(async () => {
556
+ await refreshSessionAction(ctx);
557
+ scheduleRefresh();
558
+ }, refreshIn);
559
+ } catch (_) {
560
+ refreshTimerRef.current = setTimeout(async () => {
561
+ await refreshSessionAction(ctx);
562
+ scheduleRefresh();
563
+ }, 5 * 60 * 1e3);
564
+ }
565
+ }, [ctx, storageKeys.accessToken]);
566
+ useEffect(() => {
567
+ (async () => {
568
+ const queryString = window.location.search;
569
+ if (!queryString) return;
570
+ const urlParams = new URLSearchParams(queryString);
571
+ const token_url = urlParams.get(storageKeys.accessToken);
572
+ const refresh_url = urlParams.get(storageKeys.refreshToken);
573
+ if (token_url && refresh_url && !dauthState.isAuthenticated) {
574
+ return setDauthStateAction({
575
+ ...ctx,
576
+ token: token_url,
577
+ refreshToken: refresh_url
578
+ });
579
+ }
580
+ })();
581
+ }, []);
582
+ useEffect(() => {
583
+ (async () => {
584
+ const refreshToken = localStorage.getItem(storageKeys.refreshToken);
585
+ if (refreshToken && !dauthState.isAuthenticated) {
586
+ return setAutoLoginAction(ctx);
587
+ } else {
588
+ return dispatch({
589
+ type: SET_IS_LOADING,
590
+ payload: { isLoading: false }
591
+ });
592
+ }
593
+ })();
594
+ }, []);
595
+ useEffect(() => {
596
+ if (dauthState.isAuthenticated) {
597
+ scheduleRefresh();
598
+ }
599
+ return () => {
600
+ if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
601
+ };
602
+ }, [dauthState.isAuthenticated, scheduleRefresh]);
603
+ const loginWithRedirect = useCallback(() => {
604
+ const base = `${getClientBasePath()}/${domainName}/${routes.signin}`;
605
+ const url = env ? `${base}?env=${encodeURIComponent(env)}` : base;
606
+ return window.location.replace(url);
607
+ }, [domainName, env]);
608
+ const logout = useCallback(() => {
609
+ if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
610
+ return setLogoutAction({
611
+ dispatch,
612
+ domainName,
613
+ storageKeys
614
+ });
615
+ }, [domainName, storageKeys]);
616
+ const getAccessToken = useCallback(async () => {
617
+ const token = await getAccessTokenAction(ctx);
618
+ return token;
619
+ }, [ctx]);
620
+ const updateUser = useCallback(
621
+ async (fields) => {
622
+ const token_ls = localStorage.getItem(storageKeys.accessToken);
623
+ const {
624
+ name,
625
+ lastname,
626
+ nickname,
627
+ telPrefix,
628
+ telSuffix,
629
+ language,
630
+ avatar,
631
+ birthDate,
632
+ country,
633
+ metadata
634
+ } = fields;
635
+ const user = {
636
+ name,
637
+ lastname,
638
+ nickname,
639
+ telPrefix,
640
+ telSuffix,
641
+ language,
642
+ avatar,
643
+ birthDate,
644
+ country,
645
+ metadata
646
+ };
647
+ return await setUpdateUserAction({
648
+ ...ctx,
649
+ user,
650
+ token: token_ls
651
+ });
652
+ },
653
+ [ctx, storageKeys.accessToken]
654
+ );
655
+ const updateUserWithRedirect = useCallback(() => {
656
+ const token_ls = localStorage.getItem(storageKeys.accessToken);
657
+ if (!token_ls) return;
658
+ return window.location.replace(
659
+ `${getClientBasePath()}/${domainName}/${routes.updateUser}/${token_ls}`
660
+ );
661
+ }, [domainName, storageKeys.accessToken]);
662
+ const sendEmailVerification = useCallback(async () => {
663
+ const token_ls = localStorage.getItem(storageKeys.accessToken);
664
+ if (!token_ls) return false;
665
+ return await sendEmailVerificationAction({
666
+ ...ctx,
667
+ token: token_ls
668
+ });
669
+ }, [ctx, storageKeys.accessToken]);
670
+ const deleteAccount = useCallback(async () => {
671
+ const token_ls = localStorage.getItem(storageKeys.accessToken);
672
+ if (!token_ls) return false;
673
+ if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
674
+ return await deleteAccountAction({
675
+ ...ctx,
676
+ token: token_ls
677
+ });
678
+ }, [ctx, storageKeys.accessToken]);
679
+ const memoProvider = useMemo(
680
+ () => ({
681
+ ...dauthState,
682
+ loginWithRedirect,
683
+ logout,
684
+ getAccessToken,
685
+ updateUser,
686
+ updateUserWithRedirect,
687
+ sendEmailVerification,
688
+ deleteAccount
689
+ }),
690
+ [
691
+ dauthState,
692
+ loginWithRedirect,
693
+ logout,
694
+ getAccessToken,
695
+ updateUser,
696
+ updateUserWithRedirect,
697
+ sendEmailVerification,
698
+ deleteAccount
699
+ ]
700
+ );
701
+ return /* @__PURE__ */ jsx(DauthContext.Provider, { value: memoProvider, children });
702
+ };
703
+ var DauthContext = createContext(initialDauthState_default);
704
+ var useDauth = () => {
705
+ const context = useContext(DauthContext);
706
+ if (!context) {
707
+ throw new Error("useDauth must be used inside DauthProvider");
708
+ }
709
+ return context;
710
+ };
711
+ export {
712
+ DauthProvider,
713
+ useDauth
714
+ };
715
+ //# sourceMappingURL=index.mjs.map