dauth-context-react 4.0.4 → 5.0.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.js CHANGED
@@ -38,7 +38,6 @@ var initialDauthState = {
38
38
  },
39
39
  logout: () => {
40
40
  },
41
- getAccessToken: () => Promise.resolve(""),
42
41
  updateUser: () => Promise.resolve(false),
43
42
  updateUserWithRedirect: () => {
44
43
  },
@@ -86,162 +85,108 @@ function userReducer(state, action) {
86
85
  }
87
86
  }
88
87
 
89
- // src/api/utils/config.ts
90
- var apiVersion = "v1";
91
- var serverDomain = "dauth.ovh";
92
- var _dauthUrl;
93
- function setDauthUrl(url) {
94
- _dauthUrl = url?.replace(/\/+$/, "");
95
- }
96
- function checkIsLocalhost() {
97
- if (typeof window === "undefined") return false;
98
- const hostname = window.location.hostname;
99
- return Boolean(
100
- hostname === "localhost" || hostname === "[::1]" || hostname.match(
101
- /(192)\.(168)\.(1)\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm
102
- ) || hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
88
+ // src/api/dauth.api.ts
89
+ function getCsrfToken() {
90
+ const match = document.cookie.match(
91
+ /(?:^|;\s*)(?:__Host-csrf|csrf-token)=([^;]*)/
103
92
  );
93
+ return match?.[1] ?? "";
104
94
  }
105
- function getServerBasePath() {
106
- if (_dauthUrl) return `${_dauthUrl}/api/${apiVersion}`;
107
- const isLocalhost = checkIsLocalhost();
108
- const serverPort = 4012;
109
- const serverLocalUrl = `${window.location.protocol}//${window.location.hostname}:${serverPort}/api/${apiVersion}`;
110
- const serverProdUrl = `https://${serverDomain}/api/${apiVersion}`;
111
- return isLocalhost ? serverLocalUrl : serverProdUrl;
112
- }
113
- function getClientBasePath() {
114
- if (_dauthUrl) return _dauthUrl;
115
- const isLocalhost = checkIsLocalhost();
116
- const clientPort = 5185;
117
- const clientLocalUrl = `${window.location.protocol}//${window.location.hostname}:${clientPort}`;
118
- const clientProdUrl = `https://${serverDomain}`;
119
- return isLocalhost ? clientLocalUrl : clientProdUrl;
95
+ async function exchangeCodeAPI(basePath, code) {
96
+ const response = await fetch(`${basePath}/exchange-code`, {
97
+ method: "POST",
98
+ headers: { "Content-Type": "application/json" },
99
+ credentials: "include",
100
+ body: JSON.stringify({ code })
101
+ });
102
+ const data = await response.json();
103
+ return { response, data };
120
104
  }
121
-
122
- // src/api/dauth.api.ts
123
- var getUserAPI = async (domainName, token) => {
124
- const params = {
105
+ async function getSessionAPI(basePath) {
106
+ const response = await fetch(`${basePath}/session`, {
125
107
  method: "GET",
126
- headers: {
127
- Authorization: token,
128
- "Content-Type": "application/json"
129
- }
130
- };
131
- const response = await fetch(
132
- `${getServerBasePath()}/app/${domainName}/user`,
133
- params
134
- );
108
+ credentials: "include"
109
+ });
135
110
  const data = await response.json();
136
111
  return { response, data };
137
- };
138
- var updateUserAPI = async (domainName, user, token) => {
139
- const params = {
112
+ }
113
+ async function logoutAPI(basePath) {
114
+ const response = await fetch(`${basePath}/logout`, {
115
+ method: "POST",
116
+ headers: {
117
+ "Content-Type": "application/json",
118
+ "X-CSRF-Token": getCsrfToken()
119
+ },
120
+ credentials: "include"
121
+ });
122
+ return { response };
123
+ }
124
+ async function updateUserAPI(basePath, user) {
125
+ const response = await fetch(`${basePath}/user`, {
140
126
  method: "PATCH",
141
127
  headers: {
142
- Authorization: token,
143
- "Content-Type": "application/json"
128
+ "Content-Type": "application/json",
129
+ "X-CSRF-Token": getCsrfToken()
144
130
  },
131
+ credentials: "include",
145
132
  body: JSON.stringify(user)
146
- };
147
- const response = await fetch(
148
- `${getServerBasePath()}/app/${domainName}/user`,
149
- params
150
- );
151
- const data = await response.json();
152
- return { response, data };
153
- };
154
- var refreshTokenAPI = async (domainName, refreshToken) => {
155
- const params = {
156
- method: "POST",
157
- headers: { "Content-Type": "application/json" },
158
- body: JSON.stringify({ refreshToken })
159
- };
160
- const response = await fetch(
161
- `${getServerBasePath()}/app/${domainName}/refresh-token`,
162
- params
163
- );
133
+ });
164
134
  const data = await response.json();
165
135
  return { response, data };
166
- };
167
- var deleteAccountAPI = async (domainName, token) => {
168
- const params = {
136
+ }
137
+ async function deleteAccountAPI(basePath) {
138
+ const response = await fetch(`${basePath}/user`, {
169
139
  method: "DELETE",
170
- headers: {
171
- Authorization: token,
172
- "Content-Type": "application/json"
173
- }
174
- };
175
- const response = await fetch(
176
- `${getServerBasePath()}/app/${domainName}/user`,
177
- params
178
- );
140
+ headers: { "X-CSRF-Token": getCsrfToken() },
141
+ credentials: "include"
142
+ });
179
143
  const data = await response.json();
180
144
  return { response, data };
181
- };
182
- var exchangeCodeAPI = async (domainName, code) => {
183
- const params = {
184
- method: "POST",
185
- headers: { "Content-Type": "application/json" },
186
- body: JSON.stringify({ code })
187
- };
145
+ }
146
+ async function profileRedirectAPI(basePath) {
188
147
  const response = await fetch(
189
- `${getServerBasePath()}/app/${domainName}/exchange-code`,
190
- params
148
+ `${basePath}/profile-redirect`,
149
+ {
150
+ method: "GET",
151
+ headers: { "X-CSRF-Token": getCsrfToken() },
152
+ credentials: "include"
153
+ }
191
154
  );
192
155
  const data = await response.json();
193
156
  return { response, data };
194
- };
195
- var logoutAPI = async (domainName, refreshToken) => {
196
- const params = {
197
- method: "POST",
198
- headers: { "Content-Type": "application/json" },
199
- body: JSON.stringify({ refreshToken })
200
- };
201
- const response = await fetch(
202
- `${getServerBasePath()}/app/${domainName}/logout`,
203
- params
204
- );
205
- return { response };
206
- };
157
+ }
207
158
 
208
159
  // src/reducer/dauth.actions.ts
209
- async function exchangeCodeAction({
210
- dispatch,
211
- code,
212
- domainName,
213
- storageKeys,
214
- onError
215
- }) {
160
+ async function exchangeCodeAction(ctx, code) {
161
+ const { dispatch, authProxyPath, onError } = ctx;
216
162
  dispatch({
217
163
  type: SET_IS_LOADING,
218
164
  payload: { isLoading: true }
219
165
  });
220
166
  try {
221
- window.history.replaceState({}, document.title, window.location.pathname);
222
- const exchangeResult = await exchangeCodeAPI(domainName, code);
223
- if (exchangeResult.response.status !== 200) {
224
- return resetUser(dispatch, storageKeys);
225
- }
226
- const { accessToken, refreshToken } = exchangeResult.data;
227
- localStorage.setItem(storageKeys.accessToken, accessToken);
228
- localStorage.setItem(storageKeys.refreshToken, refreshToken);
229
- const getUserFetch = await getUserAPI(domainName, accessToken);
230
- if (getUserFetch.response.status === 200) {
167
+ window.history.replaceState(
168
+ {},
169
+ document.title,
170
+ window.location.pathname
171
+ );
172
+ const result = await exchangeCodeAPI(authProxyPath, code);
173
+ if (result.response.status === 200) {
231
174
  dispatch({
232
175
  type: LOGIN,
233
176
  payload: {
234
- user: getUserFetch.data.user,
235
- domain: getUserFetch.data.domain,
177
+ user: result.data.user,
178
+ domain: result.data.domain,
236
179
  isAuthenticated: true
237
180
  }
238
181
  });
239
182
  return;
240
183
  }
241
- return resetUser(dispatch, storageKeys);
184
+ resetUser(dispatch);
242
185
  } catch (error) {
243
- onError(error instanceof Error ? error : new Error(String(error)));
244
- return resetUser(dispatch, storageKeys);
186
+ onError(
187
+ error instanceof Error ? error : new Error(String(error))
188
+ );
189
+ resetUser(dispatch);
245
190
  } finally {
246
191
  dispatch({
247
192
  type: SET_IS_LOADING,
@@ -249,45 +194,31 @@ async function exchangeCodeAction({
249
194
  });
250
195
  }
251
196
  }
252
- async function setAutoLoginAction({
253
- dispatch,
254
- domainName,
255
- storageKeys,
256
- onError
257
- }) {
258
- dispatch({ type: SET_IS_LOADING, payload: { isLoading: true } });
259
- const storedRefreshToken = localStorage.getItem(storageKeys.refreshToken);
260
- if (!storedRefreshToken) {
261
- dispatch({
262
- type: SET_IS_LOADING,
263
- payload: { isLoading: false }
264
- });
265
- return resetUser(dispatch, storageKeys);
266
- }
197
+ async function autoLoginAction(ctx) {
198
+ const { dispatch, authProxyPath, onError } = ctx;
199
+ dispatch({
200
+ type: SET_IS_LOADING,
201
+ payload: { isLoading: true }
202
+ });
267
203
  try {
268
- const refreshResult = await refreshTokenAPI(domainName, storedRefreshToken);
269
- if (refreshResult.response.status === 200) {
270
- const newAccessToken = refreshResult.data.accessToken;
271
- const newRefreshToken = refreshResult.data.refreshToken;
272
- localStorage.setItem(storageKeys.accessToken, newAccessToken);
273
- localStorage.setItem(storageKeys.refreshToken, newRefreshToken);
274
- const getUserFetch = await getUserAPI(domainName, newAccessToken);
275
- if (getUserFetch.response.status === 200) {
276
- dispatch({
277
- type: LOGIN,
278
- payload: {
279
- user: getUserFetch.data.user,
280
- domain: getUserFetch.data.domain,
281
- isAuthenticated: true
282
- }
283
- });
284
- return;
285
- }
204
+ const result = await getSessionAPI(authProxyPath);
205
+ if (result.response.status === 200) {
206
+ dispatch({
207
+ type: LOGIN,
208
+ payload: {
209
+ user: result.data.user,
210
+ domain: result.data.domain,
211
+ isAuthenticated: true
212
+ }
213
+ });
214
+ return;
286
215
  }
287
- resetUser(dispatch, storageKeys);
216
+ resetUser(dispatch);
288
217
  } catch (error) {
289
- onError(error instanceof Error ? error : new Error(String(error)));
290
- resetUser(dispatch, storageKeys);
218
+ onError(
219
+ error instanceof Error ? error : new Error(String(error))
220
+ );
221
+ resetUser(dispatch);
291
222
  } finally {
292
223
  dispatch({
293
224
  type: SET_IS_LOADING,
@@ -295,19 +226,16 @@ async function setAutoLoginAction({
295
226
  });
296
227
  }
297
228
  }
298
- async function setLogoutAction({
299
- dispatch,
300
- domainName,
301
- storageKeys
302
- }) {
303
- const storedRefreshToken = localStorage.getItem(storageKeys.refreshToken);
304
- if (storedRefreshToken && domainName) {
305
- try {
306
- await logoutAPI(domainName, storedRefreshToken);
307
- } catch (_) {
308
- }
229
+ async function logoutAction(ctx) {
230
+ const { dispatch, authProxyPath } = ctx;
231
+ try {
232
+ await logoutAPI(authProxyPath);
233
+ } catch {
309
234
  }
310
- dispatch({ type: SET_IS_LOADING, payload: { isLoading: true } });
235
+ dispatch({
236
+ type: SET_IS_LOADING,
237
+ payload: { isLoading: true }
238
+ });
311
239
  dispatch({
312
240
  type: LOGIN,
313
241
  payload: {
@@ -318,126 +246,73 @@ async function setLogoutAction({
318
246
  isAuthenticated: false
319
247
  }
320
248
  });
321
- localStorage.removeItem(storageKeys.accessToken);
322
- localStorage.removeItem(storageKeys.refreshToken);
323
- return dispatch({
249
+ dispatch({
324
250
  type: SET_IS_LOADING,
325
251
  payload: { isLoading: false }
326
252
  });
327
253
  }
328
- async function refreshSessionAction({
329
- dispatch,
330
- domainName,
331
- storageKeys,
332
- onError
333
- }) {
334
- const storedRefreshToken = localStorage.getItem(storageKeys.refreshToken);
335
- if (!storedRefreshToken) {
336
- return resetUser(dispatch, storageKeys);
337
- }
338
- try {
339
- const refreshResult = await refreshTokenAPI(domainName, storedRefreshToken);
340
- if (refreshResult.response.status === 200) {
341
- localStorage.setItem(
342
- storageKeys.accessToken,
343
- refreshResult.data.accessToken
344
- );
345
- localStorage.setItem(
346
- storageKeys.refreshToken,
347
- refreshResult.data.refreshToken
348
- );
349
- return;
350
- }
351
- resetUser(dispatch, storageKeys);
352
- } catch (error) {
353
- onError(error instanceof Error ? error : new Error(String(error)));
354
- resetUser(dispatch, storageKeys);
355
- }
356
- }
357
- async function setUpdateUserAction({
358
- dispatch,
359
- domainName,
360
- user,
361
- token,
362
- onError
363
- }) {
254
+ async function updateUserAction(ctx, user) {
255
+ const { dispatch, authProxyPath, onError } = ctx;
364
256
  if (user.language) {
365
- window.document.documentElement.setAttribute("lang", user.language);
366
- }
367
- if (!token) {
368
- dispatch({
369
- type: UPDATE_USER,
370
- payload: user
371
- });
372
- return false;
257
+ window.document.documentElement.setAttribute(
258
+ "lang",
259
+ user.language
260
+ );
373
261
  }
374
262
  try {
375
- const getUserFetch = await updateUserAPI(domainName, user, token);
376
- if (getUserFetch.response.status === 200) {
263
+ const result = await updateUserAPI(authProxyPath, user);
264
+ if (result.response.status === 200) {
377
265
  dispatch({
378
266
  type: UPDATE_USER,
379
- payload: getUserFetch.data.user
267
+ payload: result.data.user
380
268
  });
381
269
  return true;
382
- } else {
383
- onError(new Error("Update user error: " + getUserFetch.data.message));
384
- return false;
385
270
  }
271
+ onError(
272
+ new Error("Update user error: " + result.data.message)
273
+ );
274
+ return false;
386
275
  } catch (error) {
387
- onError(error instanceof Error ? error : new Error("Update user error"));
276
+ onError(
277
+ error instanceof Error ? error : new Error("Update user error")
278
+ );
388
279
  return false;
389
280
  }
390
281
  }
391
- async function getAccessTokenAction({
392
- dispatch,
393
- domainName,
394
- storageKeys,
395
- onError
396
- }) {
397
- const token_ls = localStorage.getItem(storageKeys.accessToken);
398
- if (!token_ls) return "token-not-found";
282
+ async function updateUserWithRedirectAction(ctx) {
283
+ const { authProxyPath, onError } = ctx;
399
284
  try {
400
- const payloadB64 = token_ls.split(".")[1];
401
- if (payloadB64) {
402
- const payload = JSON.parse(atob(payloadB64));
403
- const expiresIn = (payload.exp || 0) * 1e3 - Date.now();
404
- if (expiresIn < 5 * 60 * 1e3) {
405
- await refreshSessionAction({
406
- dispatch,
407
- domainName,
408
- storageKeys,
409
- onError
410
- });
411
- const refreshedToken = localStorage.getItem(storageKeys.accessToken);
412
- return refreshedToken || "token-not-found";
413
- }
285
+ const result = await profileRedirectAPI(authProxyPath);
286
+ if (result.response.status === 200 && result.data.redirectUrl) {
287
+ window.location.replace(result.data.redirectUrl);
288
+ return;
414
289
  }
415
- } catch (_) {
290
+ onError(
291
+ new Error("Could not generate profile redirect")
292
+ );
293
+ } catch (error) {
294
+ onError(
295
+ error instanceof Error ? error : new Error("Profile redirect error")
296
+ );
416
297
  }
417
- return token_ls;
418
298
  }
419
- async function deleteAccountAction({
420
- dispatch,
421
- domainName,
422
- storageKeys,
423
- onError,
424
- token
425
- }) {
299
+ async function deleteAccountAction(ctx) {
300
+ const { dispatch, authProxyPath, onError } = ctx;
426
301
  try {
427
- const result = await deleteAccountAPI(domainName, token);
302
+ const result = await deleteAccountAPI(authProxyPath);
428
303
  if (result.response.status === 200) {
429
- resetUser(dispatch, storageKeys);
304
+ resetUser(dispatch);
430
305
  return true;
431
306
  }
432
307
  return false;
433
308
  } catch (error) {
434
- onError(error instanceof Error ? error : new Error("Delete account error"));
309
+ onError(
310
+ error instanceof Error ? error : new Error("Delete account error")
311
+ );
435
312
  return false;
436
313
  }
437
314
  }
438
- var resetUser = (dispatch, storageKeys) => {
439
- localStorage.removeItem(storageKeys.accessToken);
440
- localStorage.removeItem(storageKeys.refreshToken);
315
+ var resetUser = (dispatch) => {
441
316
  return dispatch({
442
317
  type: LOGIN,
443
318
  payload: {
@@ -448,120 +323,87 @@ var resetUser = (dispatch, storageKeys) => {
448
323
  });
449
324
  };
450
325
 
326
+ // src/api/utils/config.ts
327
+ var serverDomain = "dauth.ovh";
328
+ var _dauthUrl;
329
+ function setDauthUrl(url) {
330
+ _dauthUrl = url?.replace(/\/+$/, "");
331
+ }
332
+ function checkIsLocalhost() {
333
+ if (typeof window === "undefined") return false;
334
+ const hostname = window.location.hostname;
335
+ return Boolean(
336
+ hostname === "localhost" || hostname === "[::1]" || hostname.match(
337
+ /(192)\.(168)\.(1)\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm
338
+ ) || hostname.match(
339
+ /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
340
+ )
341
+ );
342
+ }
343
+ function getClientBasePath() {
344
+ if (_dauthUrl) return _dauthUrl;
345
+ const isLocalhost = checkIsLocalhost();
346
+ const clientPort = 5185;
347
+ const clientLocalUrl = `${window.location.protocol}//${window.location.hostname}:${clientPort}`;
348
+ const clientProdUrl = `https://${serverDomain}`;
349
+ return isLocalhost ? clientLocalUrl : clientProdUrl;
350
+ }
351
+
451
352
  // src/constants.ts
452
- var TOKEN_LS = "dauth_state";
453
- var REFRESH_TOKEN_LS = "dauth_refresh_token";
454
353
  var AUTH_CODE_PARAM = "code";
455
354
 
456
355
  // src/api/utils/routes.ts
457
356
  var routes = {
458
- signin: "signin",
459
- updateUser: "update-user"
357
+ signin: "signin"
460
358
  };
461
359
 
462
360
  // src/index.tsx
463
361
  var import_jsx_runtime = require("react/jsx-runtime");
464
362
  var defaultOnError = (error) => console.error(error);
465
363
  var DauthProvider = (props) => {
466
- const { domainName, children, storageKey, onError, env, dauthUrl } = props;
467
- const [dauthState, dispatch] = (0, import_react.useReducer)(userReducer, initialDauthState_default);
468
- const refreshTimerRef = (0, import_react.useRef)(null);
364
+ const {
365
+ domainName,
366
+ children,
367
+ authProxyPath = "/api/auth",
368
+ onError,
369
+ env,
370
+ dauthUrl
371
+ } = props;
372
+ const [dauthState, dispatch] = (0, import_react.useReducer)(
373
+ userReducer,
374
+ initialDauthState_default
375
+ );
469
376
  (0, import_react.useEffect)(() => {
470
377
  setDauthUrl(dauthUrl);
471
378
  }, [dauthUrl]);
472
- const storageKeys = (0, import_react.useMemo)(
473
- () => ({
474
- accessToken: storageKey?.accessToken ?? TOKEN_LS,
475
- refreshToken: storageKey?.refreshToken ?? REFRESH_TOKEN_LS
476
- }),
477
- [storageKey?.accessToken, storageKey?.refreshToken]
478
- );
479
379
  const handleError = (0, import_react.useCallback)(
480
380
  (error) => (onError ?? defaultOnError)(error),
481
381
  [onError]
482
382
  );
483
383
  const ctx = (0, import_react.useMemo)(
484
- () => ({ dispatch, domainName, storageKeys, onError: handleError }),
485
- [domainName, storageKeys, handleError]
384
+ () => ({ dispatch, authProxyPath, onError: handleError }),
385
+ [authProxyPath, handleError]
486
386
  );
487
- const scheduleRefresh = (0, import_react.useCallback)(() => {
488
- if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
489
- const token = localStorage.getItem(storageKeys.accessToken);
490
- if (!token) return;
491
- try {
492
- const payloadB64 = token.split(".")[1];
493
- if (!payloadB64) return;
494
- const payload = JSON.parse(atob(payloadB64));
495
- const expiresIn = (payload.exp || 0) * 1e3 - Date.now();
496
- const refreshIn = Math.max(expiresIn - 5 * 60 * 1e3, 1e4);
497
- refreshTimerRef.current = setTimeout(async () => {
498
- await refreshSessionAction(ctx);
499
- scheduleRefresh();
500
- }, refreshIn);
501
- } catch (_) {
502
- refreshTimerRef.current = setTimeout(
503
- async () => {
504
- await refreshSessionAction(ctx);
505
- scheduleRefresh();
506
- },
507
- 5 * 60 * 1e3
508
- );
509
- }
510
- }, [ctx, storageKeys.accessToken]);
511
- (0, import_react.useEffect)(() => {
512
- (async () => {
513
- const queryString = window.location.search;
514
- if (!queryString) return;
515
- const urlParams = new URLSearchParams(queryString);
516
- const code = urlParams.get(AUTH_CODE_PARAM);
517
- if (code && !dauthState.isAuthenticated) {
518
- return exchangeCodeAction({ ...ctx, code });
519
- }
520
- })();
521
- }, []);
522
- (0, import_react.useEffect)(() => {
523
- (async () => {
524
- const urlParams = new URLSearchParams(window.location.search);
525
- if (urlParams.get(AUTH_CODE_PARAM)) return;
526
- const refreshToken = localStorage.getItem(storageKeys.refreshToken);
527
- if (refreshToken && !dauthState.isAuthenticated) {
528
- return setAutoLoginAction(ctx);
529
- } else {
530
- return dispatch({
531
- type: SET_IS_LOADING,
532
- payload: { isLoading: false }
533
- });
534
- }
535
- })();
536
- }, []);
537
387
  (0, import_react.useEffect)(() => {
538
- if (dauthState.isAuthenticated) {
539
- scheduleRefresh();
388
+ const params = new URLSearchParams(window.location.search);
389
+ const code = params.get(AUTH_CODE_PARAM);
390
+ if (code) {
391
+ exchangeCodeAction(ctx, code);
392
+ } else {
393
+ autoLoginAction(ctx);
540
394
  }
541
- return () => {
542
- if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
543
- };
544
- }, [dauthState.isAuthenticated, scheduleRefresh]);
395
+ }, []);
545
396
  const loginWithRedirect = (0, import_react.useCallback)(() => {
546
397
  const base = `${getClientBasePath()}/${domainName}/${routes.signin}`;
547
398
  const url = env ? `${base}?env=${encodeURIComponent(env)}` : base;
548
399
  return window.location.replace(url);
549
400
  }, [domainName, env]);
550
- const logout = (0, import_react.useCallback)(() => {
551
- if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
552
- return setLogoutAction({
553
- dispatch,
554
- domainName,
555
- storageKeys
556
- });
557
- }, [domainName, storageKeys]);
558
- const getAccessToken = (0, import_react.useCallback)(async () => {
559
- const token = await getAccessTokenAction(ctx);
560
- return token;
561
- }, [ctx]);
401
+ const logout = (0, import_react.useCallback)(
402
+ () => logoutAction(ctx),
403
+ [ctx]
404
+ );
562
405
  const updateUser = (0, import_react.useCallback)(
563
406
  async (fields) => {
564
- const token_ls = localStorage.getItem(storageKeys.accessToken);
565
407
  const {
566
408
  name,
567
409
  lastname,
@@ -586,36 +428,23 @@ var DauthProvider = (props) => {
586
428
  country,
587
429
  metadata
588
430
  };
589
- return await setUpdateUserAction({
590
- ...ctx,
591
- user,
592
- token: token_ls
593
- });
431
+ return updateUserAction(ctx, user);
594
432
  },
595
- [ctx, storageKeys.accessToken]
433
+ [ctx]
434
+ );
435
+ const updateUserWithRedirect = (0, import_react.useCallback)(
436
+ () => updateUserWithRedirectAction(ctx),
437
+ [ctx]
438
+ );
439
+ const deleteAccount = (0, import_react.useCallback)(
440
+ () => deleteAccountAction(ctx),
441
+ [ctx]
596
442
  );
597
- const updateUserWithRedirect = (0, import_react.useCallback)(() => {
598
- const token_ls = localStorage.getItem(storageKeys.accessToken);
599
- if (!token_ls) return;
600
- return window.location.replace(
601
- `${getClientBasePath()}/${domainName}/${routes.updateUser}/${token_ls}`
602
- );
603
- }, [domainName, storageKeys.accessToken]);
604
- const deleteAccount = (0, import_react.useCallback)(async () => {
605
- const token_ls = localStorage.getItem(storageKeys.accessToken);
606
- if (!token_ls) return false;
607
- if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
608
- return await deleteAccountAction({
609
- ...ctx,
610
- token: token_ls
611
- });
612
- }, [ctx, storageKeys.accessToken]);
613
443
  const memoProvider = (0, import_react.useMemo)(
614
444
  () => ({
615
445
  ...dauthState,
616
446
  loginWithRedirect,
617
447
  logout,
618
- getAccessToken,
619
448
  updateUser,
620
449
  updateUserWithRedirect,
621
450
  deleteAccount
@@ -624,7 +453,6 @@ var DauthProvider = (props) => {
624
453
  dauthState,
625
454
  loginWithRedirect,
626
455
  logout,
627
- getAccessToken,
628
456
  updateUser,
629
457
  updateUserWithRedirect,
630
458
  deleteAccount