@djangocfg/api 2.1.591 → 2.1.592
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/auth.cjs +214 -154
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +12 -1
- package/dist/auth.d.ts +12 -1
- package/dist/auth.mjs +137 -77
- package/dist/auth.mjs.map +1 -1
- package/dist/clients.cjs +19 -5
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.mjs +19 -5
- package/dist/clients.mjs.map +1 -1
- package/dist/hooks.cjs +19 -5
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.mjs +19 -5
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.cjs +19 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +19 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/_api/generated/helpers/auth.ts +17 -4
- package/src/auth/__tests__/timezone.test.ts +18 -0
- package/src/auth/hooks/index.ts +3 -0
- package/src/auth/hooks/useTimezone.ts +67 -0
package/dist/auth.cjs
CHANGED
|
@@ -205,6 +205,7 @@ __export(auth_exports, {
|
|
|
205
205
|
useQueryParams: () => useQueryParams,
|
|
206
206
|
useSession: () => useSession,
|
|
207
207
|
useSessionStorage: () => useSessionStorage,
|
|
208
|
+
useTimezone: () => useTimezone,
|
|
208
209
|
useTwoFactor: () => useTwoFactor,
|
|
209
210
|
useTwoFactorChallenge: () => useTwoFactorChallenge,
|
|
210
211
|
useTwoFactorSetup: () => useTwoFactorSetup,
|
|
@@ -229,7 +230,7 @@ var AUTH_CONSTANTS = {
|
|
|
229
230
|
|
|
230
231
|
// src/auth/context/AuthContext.tsx
|
|
231
232
|
var import_navigation4 = require("next/navigation");
|
|
232
|
-
var
|
|
233
|
+
var import_react18 = require("react");
|
|
233
234
|
|
|
234
235
|
// src/_api/generated/helpers/errors.ts
|
|
235
236
|
var APIError = class extends Error {
|
|
@@ -593,6 +594,14 @@ function defaultBaseUrl() {
|
|
|
593
594
|
return "";
|
|
594
595
|
}
|
|
595
596
|
__name(defaultBaseUrl, "defaultBaseUrl");
|
|
597
|
+
function detectTimezone() {
|
|
598
|
+
try {
|
|
599
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone || null;
|
|
600
|
+
} catch {
|
|
601
|
+
return null;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
__name(detectTimezone, "detectTimezone");
|
|
596
605
|
function defaultApiKey() {
|
|
597
606
|
try {
|
|
598
607
|
if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_API_KEY) {
|
|
@@ -604,6 +613,7 @@ function defaultApiKey() {
|
|
|
604
613
|
}
|
|
605
614
|
__name(defaultApiKey, "defaultApiKey");
|
|
606
615
|
var _localeOverride = null;
|
|
616
|
+
var _timezoneOverride = null;
|
|
607
617
|
var _apiKeyOverride = null;
|
|
608
618
|
var _baseUrlOverride = null;
|
|
609
619
|
var _withCredentials = true;
|
|
@@ -830,6 +840,14 @@ var auth = {
|
|
|
830
840
|
setLocale(locale) {
|
|
831
841
|
_localeOverride = locale;
|
|
832
842
|
},
|
|
843
|
+
// ── Time zone ─────────────────────────────────────────────────────
|
|
844
|
+
// IANA name sent as `X-Timezone`. `null` override = follow the browser.
|
|
845
|
+
getTimezone() {
|
|
846
|
+
return _timezoneOverride ?? detectTimezone();
|
|
847
|
+
},
|
|
848
|
+
setTimezone(timezone) {
|
|
849
|
+
_timezoneOverride = timezone;
|
|
850
|
+
},
|
|
833
851
|
// ── Base URL ──────────────────────────────────────────────────────
|
|
834
852
|
getBaseUrl() {
|
|
835
853
|
const url = _baseUrlOverride ?? defaultBaseUrl();
|
|
@@ -1037,11 +1055,8 @@ function installAuthOnClient(client2) {
|
|
|
1037
1055
|
if (locale) request.headers.set("Accept-Language", locale);
|
|
1038
1056
|
const apiKey = auth.getApiKey();
|
|
1039
1057
|
if (apiKey && !request.headers.has("X-API-Key")) request.headers.set("X-API-Key", apiKey);
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
if (tz) request.headers.set("X-Timezone", tz);
|
|
1043
|
-
} catch {
|
|
1044
|
-
}
|
|
1058
|
+
const tz = auth.getTimezone();
|
|
1059
|
+
if (tz) request.headers.set("X-Timezone", tz);
|
|
1045
1060
|
request.headers.set("X-Client-Time", (/* @__PURE__ */ new Date()).toISOString());
|
|
1046
1061
|
if (dpopEnabled() && typeof window !== "undefined") {
|
|
1047
1062
|
const proof = await _makeDpopProof(request.method, request.url);
|
|
@@ -1252,9 +1267,54 @@ function useSession() {
|
|
|
1252
1267
|
}
|
|
1253
1268
|
__name(useSession, "useSession");
|
|
1254
1269
|
|
|
1270
|
+
// src/auth/hooks/useTimezone.ts
|
|
1271
|
+
var import_react2 = require("react");
|
|
1272
|
+
var STORAGE_KEY = "djangocfg.timezone";
|
|
1273
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
1274
|
+
function read() {
|
|
1275
|
+
try {
|
|
1276
|
+
return localStorage.getItem(STORAGE_KEY) || null;
|
|
1277
|
+
} catch {
|
|
1278
|
+
return null;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
__name(read, "read");
|
|
1282
|
+
function hydrate() {
|
|
1283
|
+
if (typeof window === "undefined") return;
|
|
1284
|
+
auth.setTimezone(read());
|
|
1285
|
+
}
|
|
1286
|
+
__name(hydrate, "hydrate");
|
|
1287
|
+
hydrate();
|
|
1288
|
+
function write(timezone) {
|
|
1289
|
+
try {
|
|
1290
|
+
if (timezone) localStorage.setItem(STORAGE_KEY, timezone);
|
|
1291
|
+
else localStorage.removeItem(STORAGE_KEY);
|
|
1292
|
+
} catch {
|
|
1293
|
+
}
|
|
1294
|
+
auth.setTimezone(timezone);
|
|
1295
|
+
listeners.forEach((l) => l());
|
|
1296
|
+
}
|
|
1297
|
+
__name(write, "write");
|
|
1298
|
+
function subscribe(listener) {
|
|
1299
|
+
listeners.add(listener);
|
|
1300
|
+
return () => listeners.delete(listener);
|
|
1301
|
+
}
|
|
1302
|
+
__name(subscribe, "subscribe");
|
|
1303
|
+
function useTimezone() {
|
|
1304
|
+
const preference = (0, import_react2.useSyncExternalStore)(subscribe, read, () => null);
|
|
1305
|
+
const setTimezone = (0, import_react2.useCallback)((tz) => write(tz), []);
|
|
1306
|
+
return {
|
|
1307
|
+
timezone: preference ?? auth.getTimezone(),
|
|
1308
|
+
preference,
|
|
1309
|
+
isAuto: preference === null,
|
|
1310
|
+
setTimezone
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
__name(useTimezone, "useTimezone");
|
|
1314
|
+
|
|
1255
1315
|
// src/auth/hooks/useCfgRouter.ts
|
|
1256
1316
|
var import_navigation = require("next/navigation");
|
|
1257
|
-
var
|
|
1317
|
+
var import_react3 = require("react");
|
|
1258
1318
|
function getBasePath() {
|
|
1259
1319
|
if (typeof process === "undefined") {
|
|
1260
1320
|
return "";
|
|
@@ -1273,37 +1333,37 @@ function withBasePath(path, basePath) {
|
|
|
1273
1333
|
__name(withBasePath, "withBasePath");
|
|
1274
1334
|
function useCfgRouter() {
|
|
1275
1335
|
const router = (0, import_navigation.useRouter)();
|
|
1276
|
-
const basePath = (0,
|
|
1277
|
-
const push = (0,
|
|
1336
|
+
const basePath = (0, import_react3.useMemo)(() => getBasePath(), []);
|
|
1337
|
+
const push = (0, import_react3.useCallback)((href, options) => {
|
|
1278
1338
|
if (basePath) {
|
|
1279
1339
|
window.location.href = withBasePath(href, basePath);
|
|
1280
1340
|
} else {
|
|
1281
1341
|
router.push(href, options);
|
|
1282
1342
|
}
|
|
1283
1343
|
}, [router, basePath]);
|
|
1284
|
-
const replace = (0,
|
|
1344
|
+
const replace = (0, import_react3.useCallback)((href, options) => {
|
|
1285
1345
|
if (basePath) {
|
|
1286
1346
|
window.location.replace(withBasePath(href, basePath));
|
|
1287
1347
|
} else {
|
|
1288
1348
|
router.replace(href, options);
|
|
1289
1349
|
}
|
|
1290
1350
|
}, [router, basePath]);
|
|
1291
|
-
const hardPush = (0,
|
|
1351
|
+
const hardPush = (0, import_react3.useCallback)((href) => {
|
|
1292
1352
|
window.location.href = withBasePath(href, basePath);
|
|
1293
1353
|
}, [basePath]);
|
|
1294
|
-
const hardReplace = (0,
|
|
1354
|
+
const hardReplace = (0, import_react3.useCallback)((href) => {
|
|
1295
1355
|
window.location.replace(withBasePath(href, basePath));
|
|
1296
1356
|
}, [basePath]);
|
|
1297
|
-
const prefetch = (0,
|
|
1357
|
+
const prefetch = (0, import_react3.useCallback)((href) => {
|
|
1298
1358
|
router.prefetch(href);
|
|
1299
1359
|
}, [router]);
|
|
1300
|
-
const back = (0,
|
|
1360
|
+
const back = (0, import_react3.useCallback)(() => {
|
|
1301
1361
|
router.back();
|
|
1302
1362
|
}, [router]);
|
|
1303
|
-
const forward = (0,
|
|
1363
|
+
const forward = (0, import_react3.useCallback)(() => {
|
|
1304
1364
|
router.forward();
|
|
1305
1365
|
}, [router]);
|
|
1306
|
-
const refresh = (0,
|
|
1366
|
+
const refresh = (0, import_react3.useCallback)(() => {
|
|
1307
1367
|
router.refresh();
|
|
1308
1368
|
}, [router]);
|
|
1309
1369
|
return {
|
|
@@ -1321,17 +1381,17 @@ __name(useCfgRouter, "useCfgRouter");
|
|
|
1321
1381
|
|
|
1322
1382
|
// src/auth/hooks/useQueryParams.ts
|
|
1323
1383
|
var import_navigation2 = require("next/navigation");
|
|
1324
|
-
var
|
|
1384
|
+
var import_react4 = require("react");
|
|
1325
1385
|
function useQueryParams() {
|
|
1326
1386
|
const pathname = (0, import_navigation2.usePathname)();
|
|
1327
|
-
const [queryParams, setQueryParams] = (0,
|
|
1387
|
+
const [queryParams, setQueryParams] = (0, import_react4.useState)(() => {
|
|
1328
1388
|
if (typeof window === "undefined") {
|
|
1329
1389
|
return new URLSearchParams();
|
|
1330
1390
|
}
|
|
1331
1391
|
return new URLSearchParams(window.location.search);
|
|
1332
1392
|
});
|
|
1333
|
-
const lastSearchRef = (0,
|
|
1334
|
-
(0,
|
|
1393
|
+
const lastSearchRef = (0, import_react4.useRef)("");
|
|
1394
|
+
(0, import_react4.useEffect)(() => {
|
|
1335
1395
|
if (typeof window === "undefined") return;
|
|
1336
1396
|
const updateQueryParams = /* @__PURE__ */ __name(() => {
|
|
1337
1397
|
const currentSearch = window.location.search;
|
|
@@ -1365,16 +1425,16 @@ function useQueryParams() {
|
|
|
1365
1425
|
__name(useQueryParams, "useQueryParams");
|
|
1366
1426
|
|
|
1367
1427
|
// src/auth/hooks/useAuthFormState.ts
|
|
1368
|
-
var
|
|
1428
|
+
var import_react5 = require("react");
|
|
1369
1429
|
var formatCountdown = /* @__PURE__ */ __name((s) => {
|
|
1370
1430
|
if (s <= 0) return "";
|
|
1371
1431
|
const m = Math.floor(s / 60);
|
|
1372
1432
|
return m > 0 ? `${m}:${String(s % 60).padStart(2, "0")}` : `${s}s`;
|
|
1373
1433
|
}, "formatCountdown");
|
|
1374
1434
|
var useCountdown = /* @__PURE__ */ __name(() => {
|
|
1375
|
-
const [seconds, setSeconds] = (0,
|
|
1376
|
-
const timerRef = (0,
|
|
1377
|
-
const start = (0,
|
|
1435
|
+
const [seconds, setSeconds] = (0, import_react5.useState)(0);
|
|
1436
|
+
const timerRef = (0, import_react5.useRef)(null);
|
|
1437
|
+
const start = (0, import_react5.useCallback)((from) => {
|
|
1378
1438
|
if (timerRef.current) clearInterval(timerRef.current);
|
|
1379
1439
|
setSeconds(from);
|
|
1380
1440
|
timerRef.current = setInterval(() => {
|
|
@@ -1388,24 +1448,24 @@ var useCountdown = /* @__PURE__ */ __name(() => {
|
|
|
1388
1448
|
});
|
|
1389
1449
|
}, 1e3);
|
|
1390
1450
|
}, []);
|
|
1391
|
-
(0,
|
|
1451
|
+
(0, import_react5.useEffect)(() => () => {
|
|
1392
1452
|
if (timerRef.current) clearInterval(timerRef.current);
|
|
1393
1453
|
}, []);
|
|
1394
1454
|
return { seconds, start };
|
|
1395
1455
|
}, "useCountdown");
|
|
1396
1456
|
var useAuthFormState = /* @__PURE__ */ __name((initialIdentifier = "") => {
|
|
1397
|
-
const [identifier, setIdentifier] = (0,
|
|
1398
|
-
const [otp, setOtp] = (0,
|
|
1399
|
-
const [password, setPassword] = (0,
|
|
1400
|
-
const [isLoading, setIsLoading] = (0,
|
|
1401
|
-
const [acceptedTerms, setAcceptedTerms] = (0,
|
|
1402
|
-
const [marketingConsent, setMarketingConsent] = (0,
|
|
1403
|
-
const [step, setStep] = (0,
|
|
1404
|
-
const [error, setError] = (0,
|
|
1405
|
-
const [webmail, setWebmail] = (0,
|
|
1457
|
+
const [identifier, setIdentifier] = (0, import_react5.useState)(initialIdentifier);
|
|
1458
|
+
const [otp, setOtp] = (0, import_react5.useState)("");
|
|
1459
|
+
const [password, setPassword] = (0, import_react5.useState)("");
|
|
1460
|
+
const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
|
|
1461
|
+
const [acceptedTerms, setAcceptedTerms] = (0, import_react5.useState)(true);
|
|
1462
|
+
const [marketingConsent, setMarketingConsent] = (0, import_react5.useState)(null);
|
|
1463
|
+
const [step, setStep] = (0, import_react5.useState)("identifier");
|
|
1464
|
+
const [error, setError] = (0, import_react5.useState)("");
|
|
1465
|
+
const [webmail, setWebmail] = (0, import_react5.useState)(null);
|
|
1406
1466
|
const rateLimit = useCountdown();
|
|
1407
1467
|
const resend = useCountdown();
|
|
1408
|
-
const clearError = (0,
|
|
1468
|
+
const clearError = (0, import_react5.useCallback)(() => setError(""), []);
|
|
1409
1469
|
return {
|
|
1410
1470
|
// State
|
|
1411
1471
|
identifier,
|
|
@@ -1439,10 +1499,10 @@ var useAuthFormState = /* @__PURE__ */ __name((initialIdentifier = "") => {
|
|
|
1439
1499
|
}, "useAuthFormState");
|
|
1440
1500
|
|
|
1441
1501
|
// src/auth/hooks/useAuthValidation.ts
|
|
1442
|
-
var
|
|
1502
|
+
var import_react6 = require("react");
|
|
1443
1503
|
var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
1444
1504
|
var useAuthValidation = /* @__PURE__ */ __name(() => {
|
|
1445
|
-
const validateIdentifier2 = (0,
|
|
1505
|
+
const validateIdentifier2 = (0, import_react6.useCallback)((id) => {
|
|
1446
1506
|
return EMAIL_REGEX.test(id);
|
|
1447
1507
|
}, []);
|
|
1448
1508
|
return { validateIdentifier: validateIdentifier2 };
|
|
@@ -1450,7 +1510,7 @@ var useAuthValidation = /* @__PURE__ */ __name(() => {
|
|
|
1450
1510
|
var validateIdentifier = /* @__PURE__ */ __name((id) => EMAIL_REGEX.test(id), "validateIdentifier");
|
|
1451
1511
|
|
|
1452
1512
|
// src/auth/hooks/useAuthForm.ts
|
|
1453
|
-
var
|
|
1513
|
+
var import_react9 = require("react");
|
|
1454
1514
|
|
|
1455
1515
|
// src/auth/utils/logger.ts
|
|
1456
1516
|
var import_consola2 = require("consola");
|
|
@@ -1464,7 +1524,7 @@ var authLogger = logger.withTag("auth");
|
|
|
1464
1524
|
|
|
1465
1525
|
// src/auth/hooks/useAutoAuth.ts
|
|
1466
1526
|
var import_navigation3 = require("next/navigation");
|
|
1467
|
-
var
|
|
1527
|
+
var import_react7 = require("react");
|
|
1468
1528
|
|
|
1469
1529
|
// src/auth/utils/path.ts
|
|
1470
1530
|
var normalizePath = /* @__PURE__ */ __name((path) => {
|
|
@@ -1492,14 +1552,14 @@ var useAutoAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
|
1492
1552
|
const hasOTP = !!queryOtp;
|
|
1493
1553
|
const isReady = !!pathname && hasOTP && isAllowedPath;
|
|
1494
1554
|
const otpValid = queryOtp.length === AUTH_CONSTANTS.EMAIL_OTP_LENGTH;
|
|
1495
|
-
const onOTPDetectedRef = (0,
|
|
1555
|
+
const onOTPDetectedRef = (0, import_react7.useRef)(onOTPDetected);
|
|
1496
1556
|
onOTPDetectedRef.current = onOTPDetected;
|
|
1497
|
-
(0,
|
|
1557
|
+
(0, import_react7.useEffect)(() => {
|
|
1498
1558
|
if (!isReady || !otpValid) return;
|
|
1499
1559
|
authLogger.info("OTP detected in URL on auth page:", queryOtp);
|
|
1500
1560
|
onOTPDetectedRef.current?.(queryOtp, queryEmail);
|
|
1501
1561
|
}, [isReady, otpValid, queryOtp, queryEmail]);
|
|
1502
|
-
(0,
|
|
1562
|
+
(0, import_react7.useEffect)(() => {
|
|
1503
1563
|
if (!isReady || !cleanupUrl || !queryOtp) return;
|
|
1504
1564
|
const cleanQuery = Object.fromEntries(queryParams.entries());
|
|
1505
1565
|
delete cleanQuery.otp;
|
|
@@ -1516,22 +1576,22 @@ var useAutoAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
|
1516
1576
|
}, "useAutoAuth");
|
|
1517
1577
|
|
|
1518
1578
|
// src/auth/hooks/useTwoFactorChallenge.ts
|
|
1519
|
-
var
|
|
1579
|
+
var import_react8 = require("react");
|
|
1520
1580
|
var current = null;
|
|
1521
|
-
var
|
|
1581
|
+
var listeners2 = /* @__PURE__ */ new Set();
|
|
1522
1582
|
var set = /* @__PURE__ */ __name((next) => {
|
|
1523
1583
|
current = next;
|
|
1524
|
-
for (const listener of [...
|
|
1584
|
+
for (const listener of [...listeners2]) listener();
|
|
1525
1585
|
}, "set");
|
|
1526
|
-
var
|
|
1527
|
-
|
|
1586
|
+
var subscribe2 = /* @__PURE__ */ __name((listener) => {
|
|
1587
|
+
listeners2.add(listener);
|
|
1528
1588
|
return () => {
|
|
1529
|
-
|
|
1589
|
+
listeners2.delete(listener);
|
|
1530
1590
|
};
|
|
1531
1591
|
}, "subscribe");
|
|
1532
1592
|
var beginTwoFactorChallenge = /* @__PURE__ */ __name((challenge) => set(challenge), "beginTwoFactorChallenge");
|
|
1533
1593
|
var endTwoFactorChallenge = /* @__PURE__ */ __name(() => set(null), "endTwoFactorChallenge");
|
|
1534
|
-
var useTwoFactorChallenge = /* @__PURE__ */ __name(() => (0,
|
|
1594
|
+
var useTwoFactorChallenge = /* @__PURE__ */ __name(() => (0, import_react8.useSyncExternalStore)(subscribe2, () => current, () => null), "useTwoFactorChallenge");
|
|
1535
1595
|
|
|
1536
1596
|
// src/auth/hooks/useAuthForm.ts
|
|
1537
1597
|
var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
@@ -1547,8 +1607,8 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1547
1607
|
} = options;
|
|
1548
1608
|
const formState = useAuthFormState();
|
|
1549
1609
|
const validation = useAuthValidation();
|
|
1550
|
-
const isAutoSubmitFromUrlRef = (0,
|
|
1551
|
-
const processedOtpKeyRef = (0,
|
|
1610
|
+
const isAutoSubmitFromUrlRef = (0, import_react9.useRef)(false);
|
|
1611
|
+
const processedOtpKeyRef = (0, import_react9.useRef)(null);
|
|
1552
1612
|
const {
|
|
1553
1613
|
requestOTP,
|
|
1554
1614
|
verifyOTP,
|
|
@@ -1573,16 +1633,16 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1573
1633
|
setWebmail
|
|
1574
1634
|
} = formState;
|
|
1575
1635
|
const { validateIdentifier: validateIdentifier2 } = validation;
|
|
1576
|
-
const saveIdentifierToStorage = (0,
|
|
1636
|
+
const saveIdentifierToStorage = (0, import_react9.useCallback)((id) => {
|
|
1577
1637
|
saveEmail(id);
|
|
1578
1638
|
}, [saveEmail]);
|
|
1579
|
-
(0,
|
|
1639
|
+
(0, import_react9.useEffect)(() => {
|
|
1580
1640
|
const savedEmail = getSavedEmail();
|
|
1581
1641
|
if (savedEmail) {
|
|
1582
1642
|
setIdentifier(savedEmail);
|
|
1583
1643
|
}
|
|
1584
1644
|
}, []);
|
|
1585
|
-
const handleIdentifierSubmit = (0,
|
|
1645
|
+
const handleIdentifierSubmit = (0, import_react9.useCallback)(async (e) => {
|
|
1586
1646
|
e.preventDefault();
|
|
1587
1647
|
if (!identifier) {
|
|
1588
1648
|
const msg = "Please enter your email address";
|
|
@@ -1648,7 +1708,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1648
1708
|
onError,
|
|
1649
1709
|
sourceUrl
|
|
1650
1710
|
]);
|
|
1651
|
-
const submitOTP = (0,
|
|
1711
|
+
const submitOTP = (0, import_react9.useCallback)(async (submitIdentifier, submitOtp) => {
|
|
1652
1712
|
if (!submitOtp || submitOtp.length < AUTH_CONSTANTS.EMAIL_OTP_LENGTH) {
|
|
1653
1713
|
const msg = `Please enter the ${AUTH_CONSTANTS.EMAIL_OTP_LENGTH}-digit verification code`;
|
|
1654
1714
|
setError(msg);
|
|
@@ -1685,11 +1745,11 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1685
1745
|
setIsLoading(false);
|
|
1686
1746
|
}
|
|
1687
1747
|
}, [verifyOTP, saveIdentifierToStorage, setError, setIsLoading, clearError, onOTPSuccess, onError, sourceUrl, redirectUrl, setStep]);
|
|
1688
|
-
const handleOTPSubmit = (0,
|
|
1748
|
+
const handleOTPSubmit = (0, import_react9.useCallback)(async (e) => {
|
|
1689
1749
|
e.preventDefault();
|
|
1690
1750
|
await submitOTP(identifier, otp);
|
|
1691
1751
|
}, [identifier, otp, submitOTP]);
|
|
1692
|
-
const submitPassword = (0,
|
|
1752
|
+
const submitPassword = (0, import_react9.useCallback)(async (submitIdentifier, submitPassword_) => {
|
|
1693
1753
|
if (!submitIdentifier || !validateIdentifier2(submitIdentifier)) {
|
|
1694
1754
|
const msg = "Please enter a valid email address";
|
|
1695
1755
|
setError(msg);
|
|
@@ -1751,11 +1811,11 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1751
1811
|
redirectUrl,
|
|
1752
1812
|
setStep
|
|
1753
1813
|
]);
|
|
1754
|
-
const handlePasswordSubmit = (0,
|
|
1814
|
+
const handlePasswordSubmit = (0, import_react9.useCallback)(async (e) => {
|
|
1755
1815
|
e.preventDefault();
|
|
1756
1816
|
await submitPassword(identifier, password);
|
|
1757
1817
|
}, [identifier, password, submitPassword]);
|
|
1758
|
-
const handleResendOTP = (0,
|
|
1818
|
+
const handleResendOTP = (0, import_react9.useCallback)(async () => {
|
|
1759
1819
|
setIsLoading(true);
|
|
1760
1820
|
clearError();
|
|
1761
1821
|
try {
|
|
@@ -1783,15 +1843,15 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1783
1843
|
setIsLoading(false);
|
|
1784
1844
|
}
|
|
1785
1845
|
}, [identifier, marketingConsent, marketingConsentOption, requestOTP, saveIdentifierToStorage, setOtp, setError, setIsLoading, clearError, startRateLimitCountdown, startResendCountdown, setWebmail, onError, sourceUrl]);
|
|
1786
|
-
const handleBackToIdentifier = (0,
|
|
1846
|
+
const handleBackToIdentifier = (0, import_react9.useCallback)(() => {
|
|
1787
1847
|
setStep("identifier");
|
|
1788
1848
|
clearError();
|
|
1789
1849
|
}, [setStep, clearError]);
|
|
1790
|
-
const forceOTPStep = (0,
|
|
1850
|
+
const forceOTPStep = (0, import_react9.useCallback)(() => {
|
|
1791
1851
|
setStep("otp");
|
|
1792
1852
|
clearError();
|
|
1793
1853
|
}, [setStep, clearError]);
|
|
1794
|
-
const handleOTPFromUrl = (0,
|
|
1854
|
+
const handleOTPFromUrl = (0, import_react9.useCallback)((detectedOtp, detectedEmail) => {
|
|
1795
1855
|
const autoIdentifier = detectedEmail || getSavedEmail() || "";
|
|
1796
1856
|
if (!autoIdentifier) {
|
|
1797
1857
|
authLogger.warn("No identifier found for auto-submit (no email in URL or storage)");
|
|
@@ -1837,7 +1897,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1837
1897
|
}, "useAuthForm");
|
|
1838
1898
|
|
|
1839
1899
|
// src/auth/hooks/useGithubAuth.ts
|
|
1840
|
-
var
|
|
1900
|
+
var import_react10 = require("react");
|
|
1841
1901
|
|
|
1842
1902
|
// src/_api/generated/core/bodySerializer.gen.ts
|
|
1843
1903
|
var serializeFormDataPair = /* @__PURE__ */ __name((data, key, value) => {
|
|
@@ -3271,9 +3331,9 @@ var OAUTH_PROVIDER_KEY = CFG_KEYS.oauthProvider.key;
|
|
|
3271
3331
|
var useGithubAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
3272
3332
|
const { sourceUrl, onSuccess, onError, onRequires2FA, redirectUrl, skipRedirect = false } = options;
|
|
3273
3333
|
const router = useCfgRouter();
|
|
3274
|
-
const [isLoading, setIsLoading] = (0,
|
|
3275
|
-
const [error, setError] = (0,
|
|
3276
|
-
const startGithubAuth = (0,
|
|
3334
|
+
const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
|
|
3335
|
+
const [error, setError] = (0, import_react10.useState)(null);
|
|
3336
|
+
const startGithubAuth = (0, import_react10.useCallback)(async () => {
|
|
3277
3337
|
setIsLoading(true);
|
|
3278
3338
|
setError(null);
|
|
3279
3339
|
auth.clearSession();
|
|
@@ -3312,7 +3372,7 @@ var useGithubAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
|
3312
3372
|
setIsLoading(false);
|
|
3313
3373
|
}
|
|
3314
3374
|
}, [sourceUrl, onError]);
|
|
3315
|
-
const handleGithubCallback = (0,
|
|
3375
|
+
const handleGithubCallback = (0, import_react10.useCallback)(async (code, state) => {
|
|
3316
3376
|
setIsLoading(true);
|
|
3317
3377
|
setError(null);
|
|
3318
3378
|
try {
|
|
@@ -3381,10 +3441,10 @@ var useGithubAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
|
3381
3441
|
}, "useGithubAuth");
|
|
3382
3442
|
|
|
3383
3443
|
// src/auth/hooks/useTwoFactorVerify.ts
|
|
3384
|
-
var
|
|
3444
|
+
var import_react12 = require("react");
|
|
3385
3445
|
|
|
3386
3446
|
// src/auth/hooks/useSessionStorage.ts
|
|
3387
|
-
var
|
|
3447
|
+
var import_react11 = require("react");
|
|
3388
3448
|
|
|
3389
3449
|
// src/auth/utils/storage.ts
|
|
3390
3450
|
var MAX_ITEM_KB = 1024;
|
|
@@ -3413,7 +3473,7 @@ __name(isWithinSizeLimit, "isWithinSizeLimit");
|
|
|
3413
3473
|
|
|
3414
3474
|
// src/auth/hooks/useSessionStorage.ts
|
|
3415
3475
|
function useSessionStorage(key, initialValue) {
|
|
3416
|
-
const [storedValue, setStoredValue] = (0,
|
|
3476
|
+
const [storedValue, setStoredValue] = (0, import_react11.useState)(() => {
|
|
3417
3477
|
if (typeof window === "undefined") {
|
|
3418
3478
|
return initialValue;
|
|
3419
3479
|
}
|
|
@@ -3620,15 +3680,15 @@ __name(isValidTotpCode, "isValidTotpCode");
|
|
|
3620
3680
|
var useTwoFactorVerify = /* @__PURE__ */ __name((options = {}) => {
|
|
3621
3681
|
const { onSuccess, onError, redirectUrl, skipRedirect = false } = options;
|
|
3622
3682
|
const router = useCfgRouter();
|
|
3623
|
-
const [isLoading, setIsLoading] = (0,
|
|
3624
|
-
const [error, setError] = (0,
|
|
3625
|
-
const [warning, setWarning] = (0,
|
|
3626
|
-
const [remainingBackupCodes, setRemainingBackupCodes] = (0,
|
|
3627
|
-
const [attemptsRemaining, setAttemptsRemaining] = (0,
|
|
3628
|
-
const clearError = (0,
|
|
3683
|
+
const [isLoading, setIsLoading] = (0, import_react12.useState)(false);
|
|
3684
|
+
const [error, setError] = (0, import_react12.useState)(null);
|
|
3685
|
+
const [warning, setWarning] = (0, import_react12.useState)(null);
|
|
3686
|
+
const [remainingBackupCodes, setRemainingBackupCodes] = (0, import_react12.useState)(null);
|
|
3687
|
+
const [attemptsRemaining, setAttemptsRemaining] = (0, import_react12.useState)(null);
|
|
3688
|
+
const clearError = (0, import_react12.useCallback)(() => {
|
|
3629
3689
|
setError(null);
|
|
3630
3690
|
}, []);
|
|
3631
|
-
const handleSuccess = (0,
|
|
3691
|
+
const handleSuccess = (0, import_react12.useCallback)((response) => {
|
|
3632
3692
|
auth.setSession({ access: response.access_token, refresh: response.refresh_token });
|
|
3633
3693
|
if (response.warning) {
|
|
3634
3694
|
setWarning(response.warning);
|
|
@@ -3650,7 +3710,7 @@ var useTwoFactorVerify = /* @__PURE__ */ __name((options = {}) => {
|
|
|
3650
3710
|
router.hardPush(finalRedirectUrl);
|
|
3651
3711
|
}
|
|
3652
3712
|
}, [onSuccess, redirectUrl, router, skipRedirect]);
|
|
3653
|
-
const verifyTOTP = (0,
|
|
3713
|
+
const verifyTOTP = (0, import_react12.useCallback)(async (sessionId, code) => {
|
|
3654
3714
|
if (!sessionId) {
|
|
3655
3715
|
const msg = "Missing 2FA session ID";
|
|
3656
3716
|
setError(msg);
|
|
@@ -3693,7 +3753,7 @@ var useTwoFactorVerify = /* @__PURE__ */ __name((options = {}) => {
|
|
|
3693
3753
|
setIsLoading(false);
|
|
3694
3754
|
}
|
|
3695
3755
|
}, [handleSuccess, onError]);
|
|
3696
|
-
const verifyBackupCode = (0,
|
|
3756
|
+
const verifyBackupCode = (0, import_react12.useCallback)(async (sessionId, backupCode) => {
|
|
3697
3757
|
if (!sessionId) {
|
|
3698
3758
|
const msg = "Missing 2FA session ID";
|
|
3699
3759
|
setError(msg);
|
|
@@ -3752,26 +3812,26 @@ var useTwoFactorVerify = /* @__PURE__ */ __name((options = {}) => {
|
|
|
3752
3812
|
}, "useTwoFactorVerify");
|
|
3753
3813
|
|
|
3754
3814
|
// src/auth/hooks/useTwoFactorSetup.ts
|
|
3755
|
-
var
|
|
3815
|
+
var import_react13 = require("react");
|
|
3756
3816
|
var useTwoFactorSetup = /* @__PURE__ */ __name((options = {}) => {
|
|
3757
3817
|
const { onComplete, onError } = options;
|
|
3758
|
-
const [isLoading, setIsLoading] = (0,
|
|
3759
|
-
const [error, setError] = (0,
|
|
3760
|
-
const [setupData, setSetupData] = (0,
|
|
3761
|
-
const [backupCodes, setBackupCodes] = (0,
|
|
3762
|
-
const [backupCodesWarning, setBackupCodesWarning] = (0,
|
|
3763
|
-
const [setupStep, setSetupStep] = (0,
|
|
3764
|
-
const clearError = (0,
|
|
3818
|
+
const [isLoading, setIsLoading] = (0, import_react13.useState)(false);
|
|
3819
|
+
const [error, setError] = (0, import_react13.useState)(null);
|
|
3820
|
+
const [setupData, setSetupData] = (0, import_react13.useState)(null);
|
|
3821
|
+
const [backupCodes, setBackupCodes] = (0, import_react13.useState)(null);
|
|
3822
|
+
const [backupCodesWarning, setBackupCodesWarning] = (0, import_react13.useState)(null);
|
|
3823
|
+
const [setupStep, setSetupStep] = (0, import_react13.useState)("idle");
|
|
3824
|
+
const clearError = (0, import_react13.useCallback)(() => {
|
|
3765
3825
|
setError(null);
|
|
3766
3826
|
}, []);
|
|
3767
|
-
const resetSetup = (0,
|
|
3827
|
+
const resetSetup = (0, import_react13.useCallback)(() => {
|
|
3768
3828
|
setSetupData(null);
|
|
3769
3829
|
setBackupCodes(null);
|
|
3770
3830
|
setBackupCodesWarning(null);
|
|
3771
3831
|
setSetupStep("idle");
|
|
3772
3832
|
setError(null);
|
|
3773
3833
|
}, []);
|
|
3774
|
-
const startSetup = (0,
|
|
3834
|
+
const startSetup = (0, import_react13.useCallback)(async (deviceName) => {
|
|
3775
3835
|
setIsLoading(true);
|
|
3776
3836
|
setError(null);
|
|
3777
3837
|
setSetupStep("scanning");
|
|
@@ -3803,7 +3863,7 @@ var useTwoFactorSetup = /* @__PURE__ */ __name((options = {}) => {
|
|
|
3803
3863
|
setIsLoading(false);
|
|
3804
3864
|
}
|
|
3805
3865
|
}, [onError]);
|
|
3806
|
-
const confirmSetup = (0,
|
|
3866
|
+
const confirmSetup = (0, import_react13.useCallback)(async (code) => {
|
|
3807
3867
|
if (!setupData) {
|
|
3808
3868
|
const msg = "Setup not started. Call startSetup() first.";
|
|
3809
3869
|
setError(msg);
|
|
@@ -3859,16 +3919,16 @@ var useTwoFactorSetup = /* @__PURE__ */ __name((options = {}) => {
|
|
|
3859
3919
|
}, "useTwoFactorSetup");
|
|
3860
3920
|
|
|
3861
3921
|
// src/auth/hooks/useTwoFactorStatus.ts
|
|
3862
|
-
var
|
|
3922
|
+
var import_react14 = require("react");
|
|
3863
3923
|
var useTwoFactorStatus = /* @__PURE__ */ __name(() => {
|
|
3864
|
-
const [isLoading, setIsLoading] = (0,
|
|
3865
|
-
const [error, setError] = (0,
|
|
3866
|
-
const [has2FAEnabled, setHas2FAEnabled] = (0,
|
|
3867
|
-
const [devices, setDevices] = (0,
|
|
3868
|
-
const clearError = (0,
|
|
3924
|
+
const [isLoading, setIsLoading] = (0, import_react14.useState)(false);
|
|
3925
|
+
const [error, setError] = (0, import_react14.useState)(null);
|
|
3926
|
+
const [has2FAEnabled, setHas2FAEnabled] = (0, import_react14.useState)(null);
|
|
3927
|
+
const [devices, setDevices] = (0, import_react14.useState)([]);
|
|
3928
|
+
const clearError = (0, import_react14.useCallback)(() => {
|
|
3869
3929
|
setError(null);
|
|
3870
3930
|
}, []);
|
|
3871
|
-
const fetchStatus = (0,
|
|
3931
|
+
const fetchStatus = (0, import_react14.useCallback)(async () => {
|
|
3872
3932
|
setIsLoading(true);
|
|
3873
3933
|
setError(null);
|
|
3874
3934
|
try {
|
|
@@ -3893,7 +3953,7 @@ var useTwoFactorStatus = /* @__PURE__ */ __name(() => {
|
|
|
3893
3953
|
setIsLoading(false);
|
|
3894
3954
|
}
|
|
3895
3955
|
}, []);
|
|
3896
|
-
const disable2FA = (0,
|
|
3956
|
+
const disable2FA = (0, import_react14.useCallback)(async (code) => {
|
|
3897
3957
|
if (!isValidTotpCode(code)) {
|
|
3898
3958
|
setError("Please enter a 6-digit code");
|
|
3899
3959
|
return false;
|
|
@@ -3936,9 +3996,9 @@ var useTwoFactor = /* @__PURE__ */ __name((options = {}) => {
|
|
|
3936
3996
|
}, "useTwoFactor");
|
|
3937
3997
|
|
|
3938
3998
|
// src/auth/hooks/useLocalStorage.ts
|
|
3939
|
-
var
|
|
3999
|
+
var import_react15 = require("react");
|
|
3940
4000
|
function useLocalStorage(key, initialValue) {
|
|
3941
|
-
const [storedValue, setStoredValue] = (0,
|
|
4001
|
+
const [storedValue, setStoredValue] = (0, import_react15.useState)(() => {
|
|
3942
4002
|
if (typeof window === "undefined") {
|
|
3943
4003
|
return initialValue;
|
|
3944
4004
|
}
|
|
@@ -4219,15 +4279,15 @@ function getCacheMetadata() {
|
|
|
4219
4279
|
__name(getCacheMetadata, "getCacheMetadata");
|
|
4220
4280
|
|
|
4221
4281
|
// src/auth/hooks/useDeleteAccount.ts
|
|
4222
|
-
var
|
|
4282
|
+
var import_react16 = require("react");
|
|
4223
4283
|
var useDeleteAccount = /* @__PURE__ */ __name(() => {
|
|
4224
|
-
const [isLoading, setIsLoading] = (0,
|
|
4225
|
-
const [error, setError] = (0,
|
|
4284
|
+
const [isLoading, setIsLoading] = (0, import_react16.useState)(false);
|
|
4285
|
+
const [error, setError] = (0, import_react16.useState)(null);
|
|
4226
4286
|
const { logout } = useAuth();
|
|
4227
|
-
const clearError = (0,
|
|
4287
|
+
const clearError = (0, import_react16.useCallback)(() => {
|
|
4228
4288
|
setError(null);
|
|
4229
4289
|
}, []);
|
|
4230
|
-
const deleteAccount = (0,
|
|
4290
|
+
const deleteAccount = (0, import_react16.useCallback)(async () => {
|
|
4231
4291
|
setIsLoading(true);
|
|
4232
4292
|
setError(null);
|
|
4233
4293
|
try {
|
|
@@ -4257,7 +4317,7 @@ var useDeleteAccount = /* @__PURE__ */ __name(() => {
|
|
|
4257
4317
|
}, "useDeleteAccount");
|
|
4258
4318
|
|
|
4259
4319
|
// src/auth/context/AccountsContext.tsx
|
|
4260
|
-
var
|
|
4320
|
+
var import_react17 = require("react");
|
|
4261
4321
|
|
|
4262
4322
|
// src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyRegenerateCreate.ts
|
|
4263
4323
|
var import_mutation = __toESM(require("swr/mutation"), 1);
|
|
@@ -4614,21 +4674,21 @@ function hasApiOrigin() {
|
|
|
4614
4674
|
}
|
|
4615
4675
|
}
|
|
4616
4676
|
__name(hasApiOrigin, "hasApiOrigin");
|
|
4617
|
-
var AccountsContext = (0,
|
|
4677
|
+
var AccountsContext = (0, import_react17.createContext)(void 0);
|
|
4618
4678
|
function AccountsProvider({ children }) {
|
|
4619
|
-
const [profile, setProfile] = (0,
|
|
4679
|
+
const [profile, setProfile] = (0, import_react17.useState)(() => {
|
|
4620
4680
|
const cached = getCachedProfile();
|
|
4621
4681
|
return cached || void 0;
|
|
4622
4682
|
});
|
|
4623
|
-
const [isLoadingProfile, setIsLoadingProfile] = (0,
|
|
4624
|
-
const [profileError, setProfileError] = (0,
|
|
4625
|
-
const profileRef = (0,
|
|
4626
|
-
const isLoadingRef = (0,
|
|
4627
|
-
const fetchSeqRef = (0,
|
|
4628
|
-
(0,
|
|
4683
|
+
const [isLoadingProfile, setIsLoadingProfile] = (0, import_react17.useState)(false);
|
|
4684
|
+
const [profileError, setProfileError] = (0, import_react17.useState)(null);
|
|
4685
|
+
const profileRef = (0, import_react17.useRef)(profile);
|
|
4686
|
+
const isLoadingRef = (0, import_react17.useRef)(false);
|
|
4687
|
+
const fetchSeqRef = (0, import_react17.useRef)(0);
|
|
4688
|
+
(0, import_react17.useEffect)(() => {
|
|
4629
4689
|
profileRef.current = profile;
|
|
4630
4690
|
}, [profile]);
|
|
4631
|
-
(0,
|
|
4691
|
+
(0, import_react17.useEffect)(() => {
|
|
4632
4692
|
isLoadingRef.current = isLoadingProfile;
|
|
4633
4693
|
}, [isLoadingProfile]);
|
|
4634
4694
|
const { trigger: triggerProfileUpdate } = useCfgAccountsProfileUpdateUpdate();
|
|
@@ -4637,7 +4697,7 @@ function AccountsProvider({ children }) {
|
|
|
4637
4697
|
const { trigger: triggerOtpRequest } = useCfgAccountsOtpRequestCreate();
|
|
4638
4698
|
const { trigger: triggerOtpVerify } = useCfgAccountsOtpVerifyCreate();
|
|
4639
4699
|
const { trigger: triggerPasswordLogin } = useCfgAccountsTokenCreate();
|
|
4640
|
-
const refreshProfile = (0,
|
|
4700
|
+
const refreshProfile = (0, import_react17.useCallback)(async (options) => {
|
|
4641
4701
|
const { callerId, force } = options || {};
|
|
4642
4702
|
if (!hasApiOrigin()) {
|
|
4643
4703
|
authLogger.debug(`No API origin configured, skipping profile fetch (caller: ${callerId})`);
|
|
@@ -4671,26 +4731,26 @@ function AccountsProvider({ children }) {
|
|
|
4671
4731
|
}
|
|
4672
4732
|
}
|
|
4673
4733
|
}, []);
|
|
4674
|
-
const updateProfile = (0,
|
|
4734
|
+
const updateProfile = (0, import_react17.useCallback)(async (data) => {
|
|
4675
4735
|
await triggerProfileUpdate({ body: data });
|
|
4676
4736
|
const user = await refreshProfile({ callerId: "updateProfile", force: true });
|
|
4677
4737
|
return user;
|
|
4678
4738
|
}, [triggerProfileUpdate, refreshProfile]);
|
|
4679
|
-
const partialUpdateProfile = (0,
|
|
4739
|
+
const partialUpdateProfile = (0, import_react17.useCallback)(async (data) => {
|
|
4680
4740
|
await triggerProfilePartialUpdate({ body: data });
|
|
4681
4741
|
const user = await refreshProfile({ callerId: "partialUpdateProfile", force: true });
|
|
4682
4742
|
return user;
|
|
4683
4743
|
}, [triggerProfilePartialUpdate, refreshProfile]);
|
|
4684
|
-
const uploadAvatar = (0,
|
|
4744
|
+
const uploadAvatar = (0, import_react17.useCallback)(async (avatar) => {
|
|
4685
4745
|
await triggerAvatar({ body: { avatar } });
|
|
4686
4746
|
const user = await refreshProfile({ callerId: "uploadAvatar", force: true });
|
|
4687
4747
|
return user;
|
|
4688
4748
|
}, [triggerAvatar, refreshProfile]);
|
|
4689
|
-
const requestOTP = (0,
|
|
4749
|
+
const requestOTP = (0, import_react17.useCallback)(async (data) => {
|
|
4690
4750
|
const result = await triggerOtpRequest({ body: data });
|
|
4691
4751
|
return result;
|
|
4692
4752
|
}, [triggerOtpRequest]);
|
|
4693
|
-
const settleLoginEnvelope = (0,
|
|
4753
|
+
const settleLoginEnvelope = (0, import_react17.useCallback)(async (result, callerId) => {
|
|
4694
4754
|
if (result.requires_2fa && result.session_id) {
|
|
4695
4755
|
authLogger.info("2FA required, session:", result.session_id);
|
|
4696
4756
|
return;
|
|
@@ -4704,17 +4764,17 @@ function AccountsProvider({ children }) {
|
|
|
4704
4764
|
}
|
|
4705
4765
|
}
|
|
4706
4766
|
}, [refreshProfile]);
|
|
4707
|
-
const verifyOTP = (0,
|
|
4767
|
+
const verifyOTP = (0, import_react17.useCallback)(async (data) => {
|
|
4708
4768
|
const result = await triggerOtpVerify({ body: data });
|
|
4709
4769
|
await settleLoginEnvelope(result, "verifyOTP");
|
|
4710
4770
|
return result;
|
|
4711
4771
|
}, [triggerOtpVerify, settleLoginEnvelope]);
|
|
4712
|
-
const loginWithPassword = (0,
|
|
4772
|
+
const loginWithPassword = (0, import_react17.useCallback)(async (data) => {
|
|
4713
4773
|
const result = await triggerPasswordLogin({ body: data });
|
|
4714
4774
|
await settleLoginEnvelope(result, "loginWithPassword");
|
|
4715
4775
|
return result;
|
|
4716
4776
|
}, [triggerPasswordLogin, settleLoginEnvelope]);
|
|
4717
|
-
const logout = (0,
|
|
4777
|
+
const logout = (0, import_react17.useCallback)(() => {
|
|
4718
4778
|
const refresh = auth.getRefreshToken();
|
|
4719
4779
|
if (refresh) {
|
|
4720
4780
|
CfgAccountsAuth.cfgAccountsTokenBlacklistCreate({ body: { refresh } }).catch(() => {
|
|
@@ -4726,7 +4786,7 @@ function AccountsProvider({ children }) {
|
|
|
4726
4786
|
setProfileError(null);
|
|
4727
4787
|
clearProfileCache();
|
|
4728
4788
|
}, []);
|
|
4729
|
-
const value = (0,
|
|
4789
|
+
const value = (0, import_react17.useMemo)(() => ({
|
|
4730
4790
|
profile,
|
|
4731
4791
|
isLoadingProfile,
|
|
4732
4792
|
profileError,
|
|
@@ -4755,7 +4815,7 @@ function AccountsProvider({ children }) {
|
|
|
4755
4815
|
}
|
|
4756
4816
|
__name(AccountsProvider, "AccountsProvider");
|
|
4757
4817
|
function useAccountsContext() {
|
|
4758
|
-
const context = (0,
|
|
4818
|
+
const context = (0, import_react17.useContext)(AccountsContext);
|
|
4759
4819
|
if (!context) {
|
|
4760
4820
|
throw new Error("useAccountsContext must be used within AccountsProvider");
|
|
4761
4821
|
}
|
|
@@ -4776,7 +4836,7 @@ var resolveAuthRoutes = /* @__PURE__ */ __name((routes) => ({
|
|
|
4776
4836
|
defaultAuthCallback: routes?.defaultAuthCallback || routes?.auth || defaultRoutes.defaultAuthCallback
|
|
4777
4837
|
}), "resolveAuthRoutes");
|
|
4778
4838
|
var EMAIL_STORAGE_KEY = CFG_KEYS.email.key;
|
|
4779
|
-
var AuthContext = (0,
|
|
4839
|
+
var AuthContext = (0, import_react18.createContext)(void 0);
|
|
4780
4840
|
var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
4781
4841
|
const accounts = useAccountsContext();
|
|
4782
4842
|
const session = useSession();
|
|
@@ -4788,28 +4848,28 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4788
4848
|
EMAIL_STORAGE_KEY,
|
|
4789
4849
|
null
|
|
4790
4850
|
);
|
|
4791
|
-
const routes = (0,
|
|
4792
|
-
const routesRef = (0,
|
|
4793
|
-
(0,
|
|
4851
|
+
const routes = (0, import_react18.useMemo)(() => resolveAuthRoutes(config?.routes), [config?.routes]);
|
|
4852
|
+
const routesRef = (0, import_react18.useRef)(routes);
|
|
4853
|
+
(0, import_react18.useEffect)(() => {
|
|
4794
4854
|
routesRef.current = routes;
|
|
4795
4855
|
}, [routes]);
|
|
4796
4856
|
const redirectManager = useAuthRedirectManager({
|
|
4797
4857
|
fallbackUrl: routes.defaultCallback,
|
|
4798
4858
|
clearOnUse: true
|
|
4799
4859
|
});
|
|
4800
|
-
const configRef = (0,
|
|
4801
|
-
(0,
|
|
4860
|
+
const configRef = (0, import_react18.useRef)(config);
|
|
4861
|
+
(0, import_react18.useEffect)(() => {
|
|
4802
4862
|
configRef.current = config;
|
|
4803
4863
|
}, [config]);
|
|
4804
|
-
const accountsRef = (0,
|
|
4805
|
-
(0,
|
|
4864
|
+
const accountsRef = (0, import_react18.useRef)(accounts);
|
|
4865
|
+
(0, import_react18.useEffect)(() => {
|
|
4806
4866
|
accountsRef.current = accounts;
|
|
4807
4867
|
}, [accounts]);
|
|
4808
|
-
const pendingManualNavRef = (0,
|
|
4809
|
-
const [profileSettled, setProfileSettled] = (0,
|
|
4868
|
+
const pendingManualNavRef = (0, import_react18.useRef)(false);
|
|
4869
|
+
const [profileSettled, setProfileSettled] = (0, import_react18.useState)(false);
|
|
4810
4870
|
const hasProfile = Boolean(accounts.profile);
|
|
4811
|
-
const profileAttemptedRef = (0,
|
|
4812
|
-
(0,
|
|
4871
|
+
const profileAttemptedRef = (0, import_react18.useRef)(false);
|
|
4872
|
+
(0, import_react18.useEffect)(() => {
|
|
4813
4873
|
if (!isAuthenticated) {
|
|
4814
4874
|
profileAttemptedRef.current = false;
|
|
4815
4875
|
const hasTokens = Boolean(auth.getToken() || auth.getRefreshToken());
|
|
@@ -4837,8 +4897,8 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4837
4897
|
};
|
|
4838
4898
|
}, [isAuthenticated, hasProfile]);
|
|
4839
4899
|
const isLoading = !profileSettled;
|
|
4840
|
-
const expiredHandledRef = (0,
|
|
4841
|
-
(0,
|
|
4900
|
+
const expiredHandledRef = (0, import_react18.useRef)(false);
|
|
4901
|
+
(0, import_react18.useEffect)(() => {
|
|
4842
4902
|
const unsubscribe = auth.onSessionExpired(() => {
|
|
4843
4903
|
if (expiredHandledRef.current) return;
|
|
4844
4904
|
expiredHandledRef.current = true;
|
|
@@ -4851,7 +4911,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4851
4911
|
});
|
|
4852
4912
|
return unsubscribe;
|
|
4853
4913
|
}, [router]);
|
|
4854
|
-
(0,
|
|
4914
|
+
(0, import_react18.useEffect)(() => {
|
|
4855
4915
|
if (!isAuthenticated || pendingManualNavRef.current) return;
|
|
4856
4916
|
if (pathname === routes.auth && !queryParams.get("flow")) {
|
|
4857
4917
|
const saved = redirectManager.hasRedirect() ? redirectManager.getRedirect() : null;
|
|
@@ -4859,7 +4919,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4859
4919
|
router.push(saved || routes.defaultCallback);
|
|
4860
4920
|
}
|
|
4861
4921
|
}, [isAuthenticated, pathname, queryParams, routes, router, redirectManager]);
|
|
4862
|
-
const loadCurrentProfile = (0,
|
|
4922
|
+
const loadCurrentProfile = (0, import_react18.useCallback)(async (callerId) => {
|
|
4863
4923
|
if (!auth.isAuthenticated()) {
|
|
4864
4924
|
throw new Error("No valid authentication token");
|
|
4865
4925
|
}
|
|
@@ -4867,7 +4927,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4867
4927
|
callerId: callerId || "AuthContext.loadCurrentProfile"
|
|
4868
4928
|
});
|
|
4869
4929
|
}, []);
|
|
4870
|
-
const checkAuthAndRedirect = (0,
|
|
4930
|
+
const checkAuthAndRedirect = (0, import_react18.useCallback)(async () => {
|
|
4871
4931
|
if (auth.isAuthenticated()) {
|
|
4872
4932
|
try {
|
|
4873
4933
|
await loadCurrentProfile("checkAuthAndRedirect");
|
|
@@ -4879,7 +4939,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4879
4939
|
router.push(routesRef.current.defaultAuthCallback);
|
|
4880
4940
|
}
|
|
4881
4941
|
}, [loadCurrentProfile, router]);
|
|
4882
|
-
const requestOTP = (0,
|
|
4942
|
+
const requestOTP = (0, import_react18.useCallback)(
|
|
4883
4943
|
async (identifier, sourceUrl, consent) => {
|
|
4884
4944
|
auth.clearSession();
|
|
4885
4945
|
try {
|
|
@@ -4921,7 +4981,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4921
4981
|
},
|
|
4922
4982
|
[]
|
|
4923
4983
|
);
|
|
4924
|
-
const verifyOTP = (0,
|
|
4984
|
+
const verifyOTP = (0, import_react18.useCallback)(
|
|
4925
4985
|
async (identifier, otpCode, sourceUrl, redirectUrl, skipRedirect) => {
|
|
4926
4986
|
try {
|
|
4927
4987
|
pendingManualNavRef.current = Boolean(skipRedirect);
|
|
@@ -4981,7 +5041,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4981
5041
|
},
|
|
4982
5042
|
[setStoredEmail, redirectManager, router]
|
|
4983
5043
|
);
|
|
4984
|
-
const login = (0,
|
|
5044
|
+
const login = (0, import_react18.useCallback)(
|
|
4985
5045
|
async (email, password, options) => {
|
|
4986
5046
|
const { redirectUrl, skipRedirect } = options || {};
|
|
4987
5047
|
try {
|
|
@@ -5046,7 +5106,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
5046
5106
|
},
|
|
5047
5107
|
[setStoredEmail, redirectManager, router]
|
|
5048
5108
|
);
|
|
5049
|
-
const refreshToken = (0,
|
|
5109
|
+
const refreshToken = (0, import_react18.useCallback)(async () => {
|
|
5050
5110
|
const access = await auth.refreshNow();
|
|
5051
5111
|
if (access) {
|
|
5052
5112
|
Analytics.event("auth_token_refresh" /* AUTH_TOKEN_REFRESH */, {
|
|
@@ -5059,7 +5119,7 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
5059
5119
|
});
|
|
5060
5120
|
return { success: false, message: "Error refreshing token" };
|
|
5061
5121
|
}, []);
|
|
5062
|
-
const logout = (0,
|
|
5122
|
+
const logout = (0, import_react18.useCallback)(() => {
|
|
5063
5123
|
Analytics.event("auth_logout" /* AUTH_LOGOUT */, {
|
|
5064
5124
|
category: "auth" /* AUTH */
|
|
5065
5125
|
});
|
|
@@ -5068,21 +5128,21 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
5068
5128
|
}, [router]);
|
|
5069
5129
|
const user = accounts.profile ?? null;
|
|
5070
5130
|
const isAdminUser = Boolean(user?.is_staff || user?.is_superuser);
|
|
5071
|
-
(0,
|
|
5131
|
+
(0, import_react18.useEffect)(() => {
|
|
5072
5132
|
applyRoleLogPolicy({ isAdmin: isAdminUser });
|
|
5073
5133
|
}, [isAdminUser]);
|
|
5074
|
-
const updateProfile = (0,
|
|
5134
|
+
const updateProfile = (0, import_react18.useCallback)(
|
|
5075
5135
|
async (data) => {
|
|
5076
5136
|
const result = await accountsRef.current.partialUpdateProfile(data);
|
|
5077
5137
|
return result;
|
|
5078
5138
|
},
|
|
5079
5139
|
[]
|
|
5080
5140
|
);
|
|
5081
|
-
const uploadAvatar = (0,
|
|
5141
|
+
const uploadAvatar = (0, import_react18.useCallback)(async (avatar) => {
|
|
5082
5142
|
const result = await accountsRef.current.uploadAvatar(avatar);
|
|
5083
5143
|
return result;
|
|
5084
5144
|
}, []);
|
|
5085
|
-
const value = (0,
|
|
5145
|
+
const value = (0, import_react18.useMemo)(
|
|
5086
5146
|
() => ({
|
|
5087
5147
|
user,
|
|
5088
5148
|
isLoading,
|
|
@@ -5138,7 +5198,7 @@ function AuthProviderRaw({ children, config, enabled = true }) {
|
|
|
5138
5198
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AccountsProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AuthProviderInternal, { config, children }) });
|
|
5139
5199
|
}
|
|
5140
5200
|
__name(AuthProviderRaw, "AuthProviderRaw");
|
|
5141
|
-
var AuthProvider = (0,
|
|
5201
|
+
var AuthProvider = (0, import_react18.memo)(AuthProviderRaw);
|
|
5142
5202
|
var defaultAuthState = {
|
|
5143
5203
|
user: null,
|
|
5144
5204
|
isLoading: false,
|
|
@@ -5194,7 +5254,7 @@ var defaultAuthState = {
|
|
|
5194
5254
|
}, "uploadAvatar")
|
|
5195
5255
|
};
|
|
5196
5256
|
var useAuth = /* @__PURE__ */ __name(() => {
|
|
5197
|
-
const context = (0,
|
|
5257
|
+
const context = (0, import_react18.useContext)(AuthContext);
|
|
5198
5258
|
if (context === void 0) {
|
|
5199
5259
|
if (isBrowser2 && isDev) {
|
|
5200
5260
|
authLogger.debug("useAuth called outside AuthProvider, returning default state");
|