@djangocfg/api 2.1.582 → 2.1.584
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/OAuthTokenResponse-WEDM6IP5.mjs +19 -0
- package/dist/OAuthTokenResponse-WEDM6IP5.mjs.map +1 -0
- package/dist/OTPVerifyResponse-P5LDNM7H.mjs +20 -0
- package/dist/OTPVerifyResponse-P5LDNM7H.mjs.map +1 -0
- package/dist/PasswordLoginResponse-33B576NG.mjs +20 -0
- package/dist/PasswordLoginResponse-33B576NG.mjs.map +1 -0
- package/dist/auth.cjs +279 -103
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +14 -41
- package/dist/auth.d.ts +14 -41
- package/dist/auth.mjs +279 -101
- package/dist/auth.mjs.map +1 -1
- package/dist/clients.cjs +242 -54
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.d.cts +13 -41
- package/dist/clients.d.ts +13 -41
- package/dist/clients.mjs +242 -54
- package/dist/clients.mjs.map +1 -1
- package/dist/hooks.cjs +242 -54
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.mjs +242 -54
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.cjs +247 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +90 -63
- package/dist/index.d.ts +90 -63
- package/dist/index.mjs +247 -54
- package/dist/index.mjs.map +1 -1
- package/dist/storage.cjs +268 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.cts +84 -0
- package/dist/storage.d.ts +84 -0
- package/dist/storage.mjs +247 -0
- package/dist/storage.mjs.map +1 -0
- package/package.json +8 -2
- package/src/__tests__/noStorageLiterals.test.ts +27 -0
- package/src/__tests__/storage.test.ts +134 -0
- package/src/__tests__/storageSsr.test.ts +14 -0
- package/src/_api/generated/_cfg_accounts/openapi.json +1 -28
- package/src/_api/generated/_cfg_accounts/schemas/OAuthCallbackRequestRequest.ts +0 -1
- package/src/_api/generated/_cfg_accounts/schemas/OAuthTokenResponse.ts +0 -1
- package/src/_api/generated/_cfg_accounts/schemas/OTPVerifyRequest.ts +0 -1
- package/src/_api/generated/_cfg_accounts/schemas/OTPVerifyResponse.ts +0 -1
- package/src/_api/generated/_cfg_accounts/schemas/PasswordLoginRequest.ts +0 -1
- package/src/_api/generated/_cfg_accounts/schemas/PasswordLoginResponse.ts +0 -1
- package/src/_api/generated/_cfg_totp/openapi.json +0 -5
- package/src/_api/generated/_cfg_totp/schemas/VerifyResponse.ts +0 -1
- package/src/_api/generated/helpers/auth.ts +28 -65
- package/src/_api/generated/helpers/index.ts +12 -0
- package/src/_api/generated/helpers/keys.ts +327 -0
- package/src/_api/generated/openapi.json +1 -33
- package/src/_api/generated/types.gen.ts +4 -59
- package/src/auth/__tests__/authRedirect.test.ts +1 -1
- package/src/auth/__tests__/passwordLogin.test.tsx +1 -3
- package/src/auth/__tests__/profileCache.test.ts +1 -1
- package/src/auth/context/AccountsContext.tsx +6 -8
- package/src/auth/context/AuthContext.tsx +3 -5
- package/src/auth/context/types.ts +1 -1
- package/src/auth/hooks/useAuthForm.ts +3 -5
- package/src/auth/hooks/useAuthFormState.ts +0 -4
- package/src/auth/hooks/useAuthRedirect.ts +3 -2
- package/src/auth/hooks/useGithubAuth.ts +14 -16
- package/src/auth/hooks/useLocalStorage.ts +7 -7
- package/src/auth/hooks/useProfileCache.ts +2 -1
- package/src/auth/hooks/useSessionStorage.ts +7 -7
- package/src/auth/hooks/useTwoFactorVerify.ts +2 -2
- package/src/auth/types/form.ts +0 -5
- package/src/storage.ts +21 -0
package/dist/auth.cjs
CHANGED
|
@@ -129,8 +129,7 @@ var init_OTPVerifyResponse = __esm({
|
|
|
129
129
|
refresh: import_zod5.z.string().nullable().optional(),
|
|
130
130
|
access: import_zod5.z.string().nullable().optional(),
|
|
131
131
|
user: UserSchema.nullable().optional(),
|
|
132
|
-
should_prompt_2fa: import_zod5.z.boolean().optional()
|
|
133
|
-
persistent_session: import_zod5.z.boolean().optional()
|
|
132
|
+
should_prompt_2fa: import_zod5.z.boolean().optional()
|
|
134
133
|
});
|
|
135
134
|
}
|
|
136
135
|
});
|
|
@@ -152,8 +151,7 @@ var init_PasswordLoginResponse = __esm({
|
|
|
152
151
|
refresh: import_zod6.z.string().nullable().optional(),
|
|
153
152
|
access: import_zod6.z.string().nullable().optional(),
|
|
154
153
|
user: UserSchema.nullable().optional(),
|
|
155
|
-
should_prompt_2fa: import_zod6.z.boolean().optional()
|
|
156
|
-
persistent_session: import_zod6.z.boolean().optional()
|
|
154
|
+
should_prompt_2fa: import_zod6.z.boolean().optional()
|
|
157
155
|
});
|
|
158
156
|
}
|
|
159
157
|
});
|
|
@@ -297,77 +295,263 @@ var APIError = class extends Error {
|
|
|
297
295
|
}
|
|
298
296
|
};
|
|
299
297
|
|
|
300
|
-
// src/_api/generated/helpers/
|
|
301
|
-
var
|
|
302
|
-
var
|
|
303
|
-
var
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
298
|
+
// src/_api/generated/helpers/keys.ts
|
|
299
|
+
var k = /* @__PURE__ */ __name((key, store, personal) => ({ key, store, personal }), "k");
|
|
300
|
+
var f = /* @__PURE__ */ __name((prefix, store, personal) => ({ prefix, store, personal }), "f");
|
|
301
|
+
var CFG_KEYS = {
|
|
302
|
+
accessToken: k("cfg.auth.access_token", "local", true),
|
|
303
|
+
refreshToken: k("cfg.auth.refresh_token", "local", true),
|
|
304
|
+
apiKey: k("cfg.auth.api_key", "local", true),
|
|
305
|
+
email: k("cfg.auth.email", "local", false),
|
|
306
|
+
emailTs: k("cfg.auth.email_ts", "local", false),
|
|
307
|
+
redirectUrl: k("cfg.auth.redirect_url", "session", true),
|
|
308
|
+
redirectUrlTs: k("cfg.auth.redirect_url_ts", "session", true),
|
|
309
|
+
oauthState: k("cfg.auth.oauth_state", "session", true),
|
|
310
|
+
oauthProvider: k("cfg.auth.oauth_provider", "session", true),
|
|
311
|
+
profileCache: k("cfg.profile.cache", "local", true),
|
|
312
|
+
monitorSessionId: k("cfg.monitor.session_id", "local", false),
|
|
313
|
+
monitorSessionCookie: k("cfg.monitor.session_id", "cookie", false),
|
|
314
|
+
monitorDebug: k("cfg.monitor.debug", "local", false),
|
|
315
|
+
uiTabId: k("cfg.ui.tab_id", "session", false),
|
|
316
|
+
uiRouterSerial: k("cfg.ui.router_serial", "session", false),
|
|
317
|
+
uiState: k("cfg.ui.state", "local", false),
|
|
318
|
+
chatSpeechLanguage: k("cfg.chat.speech_language", "local", false),
|
|
319
|
+
chatRecentTools: k("cfg.chat.recent_tools", "local", false),
|
|
320
|
+
formsSpeechDebug: k("cfg.forms.speech_debug", "local", false),
|
|
321
|
+
formsSpeechPrefs: k("cfg.forms.speech_prefs", "local", false),
|
|
322
|
+
agentPlaygroundApiKeyId: k("cfg.agent.playground_api_key_id", "session", true),
|
|
323
|
+
agentPlaygroundBearer: k("cfg.agent.playground_bearer", "session", true),
|
|
324
|
+
agentEndpointDoc: k("cfg.agent.endpoint_doc", "session", false)
|
|
325
|
+
};
|
|
326
|
+
var CFG_FAMILIES = {
|
|
327
|
+
chatDraft: f("cfg.chat.draft.", "session", true),
|
|
328
|
+
dataTree: f("cfg.data.tree.", "local", false),
|
|
329
|
+
agentEndpointDraft: f("cfg.agent.endpoint_draft.", "local", false)
|
|
330
|
+
};
|
|
331
|
+
var OWNER_RE = /^[a-z][a-z0-9_]*$/;
|
|
332
|
+
function normalizeSegment(raw) {
|
|
333
|
+
return raw.trim().toLowerCase().replace(/[^a-z0-9_]+/g, "_").replace(/^_+|_+$/g, "");
|
|
334
|
+
}
|
|
335
|
+
__name(normalizeSegment, "normalizeSegment");
|
|
336
|
+
var hasWindow = /* @__PURE__ */ __name(() => typeof window !== "undefined", "hasWindow");
|
|
337
|
+
function nativeStorage(store) {
|
|
338
|
+
if (!hasWindow()) return null;
|
|
339
|
+
try {
|
|
340
|
+
return store === "session" ? window.sessionStorage : window.localStorage;
|
|
341
|
+
} catch {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
__name(nativeStorage, "nativeStorage");
|
|
346
|
+
function cookieNames() {
|
|
347
|
+
if (!hasWindow()) return [];
|
|
348
|
+
try {
|
|
349
|
+
return document.cookie.split("; ").map((part) => decodeURIComponent(part.split("=")[0] ?? "")).filter(Boolean);
|
|
350
|
+
} catch {
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
__name(cookieNames, "cookieNames");
|
|
355
|
+
function createStorage(owner, options = {}) {
|
|
356
|
+
if (!OWNER_RE.test(owner)) {
|
|
357
|
+
throw new TypeError(`createStorage: owner "${owner}" must match ${OWNER_RE}`);
|
|
358
|
+
}
|
|
359
|
+
const prefix = `${owner}.`;
|
|
360
|
+
const pattern = owner === "cfg" ? /^cfg(\.[a-z0-9_]+)+$/ : new RegExp(`^(cfg|${owner})(\\.[a-z0-9_]+)+$`);
|
|
361
|
+
const cookieMaxAge = options.cookieMaxAgeSeconds ?? 60 * 60 * 24 * 30;
|
|
362
|
+
const specs = Object.values(options.keys ?? {});
|
|
363
|
+
const families = Object.values(options.families ?? {});
|
|
364
|
+
const specByKey = /* @__PURE__ */ new Map();
|
|
365
|
+
for (const spec of specs) specByKey.set(spec.key, [...specByKey.get(spec.key) ?? [], spec]);
|
|
366
|
+
const memory = {
|
|
367
|
+
local: /* @__PURE__ */ new Map(),
|
|
368
|
+
session: /* @__PURE__ */ new Map(),
|
|
369
|
+
cookie: /* @__PURE__ */ new Map()
|
|
370
|
+
};
|
|
371
|
+
const isValid = /* @__PURE__ */ __name((key) => pattern.test(key), "isValid");
|
|
372
|
+
const assertValid = /* @__PURE__ */ __name((key) => {
|
|
373
|
+
if (!isValid(key)) throw new TypeError(`storage key "${key}" must match ${pattern}`);
|
|
374
|
+
}, "assertValid");
|
|
375
|
+
const assertOwned = /* @__PURE__ */ __name((key) => {
|
|
376
|
+
assertValid(key);
|
|
377
|
+
if (!key.startsWith(prefix)) throw new TypeError(`storage key "${key}" is not owned by "${owner}"`);
|
|
378
|
+
}, "assertOwned");
|
|
379
|
+
function rawGet(store, key) {
|
|
380
|
+
if (!hasWindow()) return null;
|
|
381
|
+
if (store === "cookie") {
|
|
382
|
+
try {
|
|
383
|
+
const escaped = encodeURIComponent(key).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
384
|
+
const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${escaped}=([^;]*)`));
|
|
385
|
+
if (match?.[1] !== void 0) return decodeURIComponent(match[1]);
|
|
386
|
+
} catch {
|
|
387
|
+
}
|
|
388
|
+
return memory.cookie.get(key) ?? null;
|
|
312
389
|
}
|
|
313
|
-
},
|
|
314
|
-
set(key, value) {
|
|
315
|
-
if (!isBrowser) return;
|
|
316
390
|
try {
|
|
317
|
-
|
|
318
|
-
|
|
391
|
+
const value = nativeStorage(store)?.getItem(key) ?? null;
|
|
392
|
+
if (value !== null) return value;
|
|
319
393
|
} catch {
|
|
320
394
|
}
|
|
395
|
+
return memory[store].get(key) ?? null;
|
|
321
396
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if (!isBrowser) return null;
|
|
397
|
+
__name(rawGet, "rawGet");
|
|
398
|
+
function rawSet(store, key, value) {
|
|
399
|
+
if (!hasWindow()) return false;
|
|
326
400
|
try {
|
|
327
|
-
|
|
401
|
+
if (store === "cookie") {
|
|
402
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
403
|
+
document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)}; Path=/; Max-Age=${cookieMaxAge}; SameSite=Lax${secure}`;
|
|
404
|
+
if (rawGet("cookie", key) === value && !memory.cookie.has(key)) return true;
|
|
405
|
+
memory.cookie.set(key, value);
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
const native = nativeStorage(store);
|
|
409
|
+
if (!native) throw new Error("storage unavailable");
|
|
410
|
+
native.setItem(key, value);
|
|
411
|
+
memory[store].delete(key);
|
|
412
|
+
return true;
|
|
328
413
|
} catch {
|
|
329
|
-
|
|
414
|
+
memory[store].set(key, value);
|
|
415
|
+
return false;
|
|
330
416
|
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
|
|
417
|
+
}
|
|
418
|
+
__name(rawSet, "rawSet");
|
|
419
|
+
function rawRemove(store, key) {
|
|
420
|
+
memory[store].delete(key);
|
|
421
|
+
if (!hasWindow()) return;
|
|
334
422
|
try {
|
|
335
|
-
if (
|
|
336
|
-
|
|
423
|
+
if (store === "cookie") {
|
|
424
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
425
|
+
document.cookie = `${encodeURIComponent(key)}=; Path=/; Max-Age=0; SameSite=Lax${secure}`;
|
|
426
|
+
} else {
|
|
427
|
+
nativeStorage(store)?.removeItem(key);
|
|
428
|
+
}
|
|
337
429
|
} catch {
|
|
338
430
|
}
|
|
339
431
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
432
|
+
__name(rawRemove, "rawRemove");
|
|
433
|
+
function resolveStore(key, store) {
|
|
434
|
+
return store ?? specByKey.get(key)?.[0]?.store ?? "local";
|
|
435
|
+
}
|
|
436
|
+
__name(resolveStore, "resolveStore");
|
|
437
|
+
function listKeys(store, startsWith) {
|
|
438
|
+
const out = [];
|
|
345
439
|
try {
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
440
|
+
const native = nativeStorage(store);
|
|
441
|
+
if (native) {
|
|
442
|
+
for (let i = 0; i < native.length; i += 1) {
|
|
443
|
+
const name = native.key(i);
|
|
444
|
+
if (name?.startsWith(startsWith)) out.push(name);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
350
447
|
} catch {
|
|
351
|
-
return null;
|
|
352
448
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
449
|
+
for (const name of memory[store].keys()) if (name.startsWith(startsWith) && !out.includes(name)) out.push(name);
|
|
450
|
+
return out;
|
|
451
|
+
}
|
|
452
|
+
__name(listKeys, "listKeys");
|
|
453
|
+
const familyKey = /* @__PURE__ */ __name((family, id) => {
|
|
454
|
+
const part = normalizeSegment(id);
|
|
455
|
+
if (!part) throw new TypeError("storage family id is empty after normalisation");
|
|
456
|
+
return family.prefix + part;
|
|
457
|
+
}, "familyKey");
|
|
458
|
+
const api = {
|
|
459
|
+
owner,
|
|
460
|
+
key(...parts) {
|
|
461
|
+
const segments = parts.map(normalizeSegment);
|
|
462
|
+
if (segments.length === 0 || segments.some((segment) => !segment)) {
|
|
463
|
+
throw new TypeError(`storage key parts must be non-empty: ${JSON.stringify(parts)}`);
|
|
364
464
|
}
|
|
365
|
-
|
|
465
|
+
return `${prefix}${segments.join(".")}`;
|
|
466
|
+
},
|
|
467
|
+
familyKey,
|
|
468
|
+
isValid,
|
|
469
|
+
read(key, store) {
|
|
470
|
+
assertValid(key);
|
|
471
|
+
const target = resolveStore(key, store);
|
|
472
|
+
return rawGet(target, key);
|
|
473
|
+
},
|
|
474
|
+
write(key, value, store) {
|
|
475
|
+
assertOwned(key);
|
|
476
|
+
const target = resolveStore(key, store);
|
|
477
|
+
return rawSet(target, key, value);
|
|
478
|
+
},
|
|
479
|
+
remove(key, store) {
|
|
480
|
+
assertOwned(key);
|
|
481
|
+
const target = resolveStore(key, store);
|
|
482
|
+
rawRemove(target, key);
|
|
483
|
+
},
|
|
484
|
+
readJSON(key, store) {
|
|
485
|
+
const raw = api.read(key, store);
|
|
486
|
+
if (raw === null) return null;
|
|
487
|
+
try {
|
|
488
|
+
return JSON.parse(raw);
|
|
489
|
+
} catch {
|
|
490
|
+
return null;
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
writeJSON(key, value, store) {
|
|
494
|
+
return api.write(key, JSON.stringify(value), store);
|
|
495
|
+
},
|
|
496
|
+
keys(store = "local") {
|
|
497
|
+
return listKeys(store, prefix);
|
|
498
|
+
},
|
|
499
|
+
clearAll({ all = false } = {}) {
|
|
500
|
+
for (const spec of specs) {
|
|
501
|
+
if (!all && !spec.personal) continue;
|
|
502
|
+
rawRemove(spec.store, spec.key);
|
|
503
|
+
}
|
|
504
|
+
for (const family of families) {
|
|
505
|
+
if (!all && !family.personal) continue;
|
|
506
|
+
for (const name of listKeys(family.store, family.prefix)) rawRemove(family.store, name);
|
|
507
|
+
}
|
|
508
|
+
if (all) {
|
|
509
|
+
for (const store of ["local", "session"]) {
|
|
510
|
+
for (const name of listKeys(store, prefix)) rawRemove(store, name);
|
|
511
|
+
}
|
|
512
|
+
for (const name of cookieNames()) if (name.startsWith(prefix)) rawRemove("cookie", name);
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
onChange(key, listener, store = "local") {
|
|
516
|
+
assertValid(key);
|
|
517
|
+
if (!hasWindow()) return () => {
|
|
518
|
+
};
|
|
519
|
+
const handler = /* @__PURE__ */ __name((event) => {
|
|
520
|
+
if (event.storageArea !== nativeStorage(store)) return;
|
|
521
|
+
if (event.key === null || event.key === key) listener(event.key === null ? null : event.newValue);
|
|
522
|
+
}, "handler");
|
|
523
|
+
window.addEventListener("storage", handler);
|
|
524
|
+
return () => window.removeEventListener("storage", handler);
|
|
366
525
|
}
|
|
367
|
-
}
|
|
526
|
+
};
|
|
527
|
+
return api;
|
|
528
|
+
}
|
|
529
|
+
__name(createStorage, "createStorage");
|
|
530
|
+
var cfgStorage = createStorage("cfg", {
|
|
531
|
+
keys: CFG_KEYS,
|
|
532
|
+
families: CFG_FAMILIES
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
// src/_api/generated/helpers/auth.ts
|
|
536
|
+
var ACCESS_KEY = "cfg.auth.access_token";
|
|
537
|
+
var REFRESH_KEY = "cfg.auth.refresh_token";
|
|
538
|
+
var API_KEY_KEY = "cfg.auth.api_key";
|
|
539
|
+
var storage = true ? cfgStorage : createStorage2("cfg");
|
|
540
|
+
var isBrowser = typeof window !== "undefined";
|
|
541
|
+
var STORE_OF = {
|
|
542
|
+
localStorage: "local",
|
|
543
|
+
sessionStorage: "session",
|
|
544
|
+
cookie: "cookie"
|
|
368
545
|
};
|
|
369
546
|
function backendFor(mode) {
|
|
370
|
-
|
|
547
|
+
const store = STORE_OF[mode];
|
|
548
|
+
return {
|
|
549
|
+
get: /* @__PURE__ */ __name((key) => storage.read(key, store), "get"),
|
|
550
|
+
set(key, value) {
|
|
551
|
+
if (value === null) storage.remove(key, store);
|
|
552
|
+
else storage.write(key, value, store);
|
|
553
|
+
}
|
|
554
|
+
};
|
|
371
555
|
}
|
|
372
556
|
__name(backendFor, "backendFor");
|
|
373
557
|
var _storageMode = "localStorage";
|
|
@@ -556,10 +740,12 @@ var auth = {
|
|
|
556
740
|
notifySessionChanged();
|
|
557
741
|
},
|
|
558
742
|
clearTokens() {
|
|
559
|
-
for (const
|
|
743
|
+
for (const mode of ["localStorage", "sessionStorage", "cookie"]) {
|
|
744
|
+
const backend = backendFor(mode);
|
|
560
745
|
backend.set(ACCESS_KEY, null);
|
|
561
746
|
backend.set(REFRESH_KEY, null);
|
|
562
747
|
}
|
|
748
|
+
storage.clearAll();
|
|
563
749
|
notifySessionChanged();
|
|
564
750
|
},
|
|
565
751
|
/** Session-aware: token PRESENT and not past its `exp` (or a live refresh
|
|
@@ -751,7 +937,7 @@ function dpopEnabled() {
|
|
|
751
937
|
}
|
|
752
938
|
}
|
|
753
939
|
__name(dpopEnabled, "dpopEnabled");
|
|
754
|
-
var _DPOP_DB = "cfg
|
|
940
|
+
var _DPOP_DB = "cfg.auth.dpop";
|
|
755
941
|
var _DPOP_STORE = "keys";
|
|
756
942
|
var _DPOP_KEY_ID = "dpop-ec-p256";
|
|
757
943
|
function _idbOpen() {
|
|
@@ -1214,7 +1400,6 @@ var useAuthFormState = /* @__PURE__ */ __name((initialIdentifier = "") => {
|
|
|
1214
1400
|
const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
|
|
1215
1401
|
const [acceptedTerms, setAcceptedTerms] = (0, import_react4.useState)(true);
|
|
1216
1402
|
const [marketingConsent, setMarketingConsent] = (0, import_react4.useState)(null);
|
|
1217
|
-
const [rememberMe, setRememberMe] = (0, import_react4.useState)(true);
|
|
1218
1403
|
const [step, setStep] = (0, import_react4.useState)("identifier");
|
|
1219
1404
|
const [error, setError] = (0, import_react4.useState)("");
|
|
1220
1405
|
const [webmail, setWebmail] = (0, import_react4.useState)(null);
|
|
@@ -1229,7 +1414,6 @@ var useAuthFormState = /* @__PURE__ */ __name((initialIdentifier = "") => {
|
|
|
1229
1414
|
isLoading,
|
|
1230
1415
|
acceptedTerms,
|
|
1231
1416
|
marketingConsent,
|
|
1232
|
-
rememberMe,
|
|
1233
1417
|
step,
|
|
1234
1418
|
error,
|
|
1235
1419
|
rateLimitSeconds: rateLimit.seconds,
|
|
@@ -1244,7 +1428,6 @@ var useAuthFormState = /* @__PURE__ */ __name((initialIdentifier = "") => {
|
|
|
1244
1428
|
setPassword,
|
|
1245
1429
|
setAcceptedTerms,
|
|
1246
1430
|
setMarketingConsent,
|
|
1247
|
-
setRememberMe,
|
|
1248
1431
|
setError,
|
|
1249
1432
|
clearError,
|
|
1250
1433
|
setStep,
|
|
@@ -1379,7 +1562,6 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1379
1562
|
password,
|
|
1380
1563
|
acceptedTerms,
|
|
1381
1564
|
marketingConsent,
|
|
1382
|
-
rememberMe,
|
|
1383
1565
|
setIdentifier,
|
|
1384
1566
|
setOtp,
|
|
1385
1567
|
setStep,
|
|
@@ -1476,7 +1658,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1476
1658
|
setIsLoading(true);
|
|
1477
1659
|
clearError();
|
|
1478
1660
|
try {
|
|
1479
|
-
const result = await verifyOTP(submitIdentifier, submitOtp, sourceUrl, redirectUrl, true
|
|
1661
|
+
const result = await verifyOTP(submitIdentifier, submitOtp, sourceUrl, redirectUrl, true);
|
|
1480
1662
|
if (result.requires_2fa && result.session_id) {
|
|
1481
1663
|
authLogger.info("2FA required after OTP verification");
|
|
1482
1664
|
beginTwoFactorChallenge({ sessionId: result.session_id });
|
|
@@ -1502,7 +1684,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1502
1684
|
} finally {
|
|
1503
1685
|
setIsLoading(false);
|
|
1504
1686
|
}
|
|
1505
|
-
}, [verifyOTP, saveIdentifierToStorage, setError, setIsLoading, clearError, onOTPSuccess, onError, sourceUrl, redirectUrl,
|
|
1687
|
+
}, [verifyOTP, saveIdentifierToStorage, setError, setIsLoading, clearError, onOTPSuccess, onError, sourceUrl, redirectUrl, setStep]);
|
|
1506
1688
|
const handleOTPSubmit = (0, import_react8.useCallback)(async (e) => {
|
|
1507
1689
|
e.preventDefault();
|
|
1508
1690
|
await submitOTP(identifier, otp);
|
|
@@ -1525,8 +1707,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1525
1707
|
try {
|
|
1526
1708
|
const result = await login(submitIdentifier, submitPassword_, {
|
|
1527
1709
|
redirectUrl,
|
|
1528
|
-
skipRedirect: true
|
|
1529
|
-
rememberMe
|
|
1710
|
+
skipRedirect: true
|
|
1530
1711
|
});
|
|
1531
1712
|
if (result.requires_2fa && result.session_id) {
|
|
1532
1713
|
authLogger.info("2FA required after password login");
|
|
@@ -1568,7 +1749,6 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1568
1749
|
onOTPSuccess,
|
|
1569
1750
|
onError,
|
|
1570
1751
|
redirectUrl,
|
|
1571
|
-
rememberMe,
|
|
1572
1752
|
setStep
|
|
1573
1753
|
]);
|
|
1574
1754
|
const handlePasswordSubmit = (0, import_react8.useCallback)(async (e) => {
|
|
@@ -3086,8 +3266,10 @@ var logAuthFailure = /* @__PURE__ */ __name((log, message, error) => {
|
|
|
3086
3266
|
}, "logAuthFailure");
|
|
3087
3267
|
|
|
3088
3268
|
// src/auth/hooks/useGithubAuth.ts
|
|
3269
|
+
var OAUTH_STATE_KEY = CFG_KEYS.oauthState.key;
|
|
3270
|
+
var OAUTH_PROVIDER_KEY = CFG_KEYS.oauthProvider.key;
|
|
3089
3271
|
var useGithubAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
3090
|
-
const { sourceUrl,
|
|
3272
|
+
const { sourceUrl, onSuccess, onError, onRequires2FA, redirectUrl, skipRedirect = false } = options;
|
|
3091
3273
|
const router = useCfgRouter();
|
|
3092
3274
|
const [isLoading, setIsLoading] = (0, import_react9.useState)(false);
|
|
3093
3275
|
const [error, setError] = (0, import_react9.useState)(null);
|
|
@@ -3113,9 +3295,8 @@ var useGithubAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
|
3113
3295
|
}
|
|
3114
3296
|
authLogger.info("Redirecting to GitHub...", response.authorization_url);
|
|
3115
3297
|
if (typeof window !== "undefined") {
|
|
3116
|
-
sessionStorage.setItem(
|
|
3117
|
-
sessionStorage.setItem(
|
|
3118
|
-
sessionStorage.setItem("cfg.oauth.remember_me", String(rememberMe));
|
|
3298
|
+
sessionStorage.setItem(OAUTH_STATE_KEY, response.state);
|
|
3299
|
+
sessionStorage.setItem(OAUTH_PROVIDER_KEY, "github");
|
|
3119
3300
|
}
|
|
3120
3301
|
window.location.href = response.authorization_url;
|
|
3121
3302
|
} catch (err) {
|
|
@@ -3130,25 +3311,22 @@ var useGithubAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
|
3130
3311
|
} finally {
|
|
3131
3312
|
setIsLoading(false);
|
|
3132
3313
|
}
|
|
3133
|
-
}, [sourceUrl,
|
|
3314
|
+
}, [sourceUrl, onError]);
|
|
3134
3315
|
const handleGithubCallback = (0, import_react9.useCallback)(async (code, state) => {
|
|
3135
3316
|
setIsLoading(true);
|
|
3136
3317
|
setError(null);
|
|
3137
3318
|
try {
|
|
3138
3319
|
authLogger.info("Processing GitHub OAuth callback...");
|
|
3139
|
-
let rememberMeForSession = false;
|
|
3140
3320
|
if (typeof window !== "undefined") {
|
|
3141
|
-
const storedState = sessionStorage.getItem(
|
|
3321
|
+
const storedState = sessionStorage.getItem(OAUTH_STATE_KEY);
|
|
3142
3322
|
if (storedState && storedState !== state) {
|
|
3143
3323
|
throw new Error("Invalid OAuth state - possible CSRF attack");
|
|
3144
3324
|
}
|
|
3145
|
-
|
|
3146
|
-
sessionStorage.removeItem(
|
|
3147
|
-
sessionStorage.removeItem("oauth_provider");
|
|
3148
|
-
sessionStorage.removeItem("cfg.oauth.remember_me");
|
|
3325
|
+
sessionStorage.removeItem(OAUTH_STATE_KEY);
|
|
3326
|
+
sessionStorage.removeItem(OAUTH_PROVIDER_KEY);
|
|
3149
3327
|
}
|
|
3150
3328
|
const result = await CfgAccountsOauth.cfgAccountsOauthGithubCallbackCreate({
|
|
3151
|
-
body: { code, state
|
|
3329
|
+
body: { code, state },
|
|
3152
3330
|
throwOnError: true
|
|
3153
3331
|
});
|
|
3154
3332
|
const response = result.data;
|
|
@@ -3257,7 +3435,7 @@ function useSessionStorage(key, initialValue) {
|
|
|
3257
3435
|
const key2 = keys[i];
|
|
3258
3436
|
if (key2) {
|
|
3259
3437
|
sessionStorage.removeItem(key2);
|
|
3260
|
-
sessionStorage.removeItem(`${key2}
|
|
3438
|
+
sessionStorage.removeItem(`${key2}_ts`);
|
|
3261
3439
|
}
|
|
3262
3440
|
} catch {
|
|
3263
3441
|
}
|
|
@@ -3287,7 +3465,7 @@ function useSessionStorage(key, initialValue) {
|
|
|
3287
3465
|
authLogger.warn(`Data size too large for key "${key}", removing key`);
|
|
3288
3466
|
try {
|
|
3289
3467
|
window.sessionStorage.removeItem(key);
|
|
3290
|
-
window.sessionStorage.removeItem(`${key}
|
|
3468
|
+
window.sessionStorage.removeItem(`${key}_ts`);
|
|
3291
3469
|
} catch {
|
|
3292
3470
|
}
|
|
3293
3471
|
setStoredValue(valueToStore);
|
|
@@ -3297,20 +3475,20 @@ function useSessionStorage(key, initialValue) {
|
|
|
3297
3475
|
if (typeof window !== "undefined") {
|
|
3298
3476
|
try {
|
|
3299
3477
|
window.sessionStorage.setItem(key, JSON.stringify(valueToStore));
|
|
3300
|
-
window.sessionStorage.setItem(`${key}
|
|
3478
|
+
window.sessionStorage.setItem(`${key}_ts`, Date.now().toString());
|
|
3301
3479
|
} catch (storageError) {
|
|
3302
3480
|
if (isQuotaExceededError(storageError)) {
|
|
3303
3481
|
authLogger.warn("sessionStorage quota exceeded, clearing old data...");
|
|
3304
3482
|
clearOldData();
|
|
3305
3483
|
try {
|
|
3306
3484
|
window.sessionStorage.setItem(key, JSON.stringify(valueToStore));
|
|
3307
|
-
window.sessionStorage.setItem(`${key}
|
|
3485
|
+
window.sessionStorage.setItem(`${key}_ts`, Date.now().toString());
|
|
3308
3486
|
} catch (retryError) {
|
|
3309
3487
|
authLogger.error(`Failed to set sessionStorage key "${key}" after clearing old data:`, retryError);
|
|
3310
3488
|
try {
|
|
3311
3489
|
forceClearAll();
|
|
3312
3490
|
window.sessionStorage.setItem(key, JSON.stringify(valueToStore));
|
|
3313
|
-
window.sessionStorage.setItem(`${key}
|
|
3491
|
+
window.sessionStorage.setItem(`${key}_ts`, Date.now().toString());
|
|
3314
3492
|
} catch (finalError) {
|
|
3315
3493
|
authLogger.error(`Failed to set sessionStorage key "${key}" after force clearing:`, finalError);
|
|
3316
3494
|
setStoredValue(valueToStore);
|
|
@@ -3333,14 +3511,14 @@ function useSessionStorage(key, initialValue) {
|
|
|
3333
3511
|
if (typeof window !== "undefined") {
|
|
3334
3512
|
try {
|
|
3335
3513
|
window.sessionStorage.removeItem(key);
|
|
3336
|
-
window.sessionStorage.removeItem(`${key}
|
|
3514
|
+
window.sessionStorage.removeItem(`${key}_ts`);
|
|
3337
3515
|
} catch (removeError) {
|
|
3338
3516
|
if (isQuotaExceededError(removeError)) {
|
|
3339
3517
|
authLogger.warn("sessionStorage quota exceeded during removal, clearing old data...");
|
|
3340
3518
|
clearOldData();
|
|
3341
3519
|
try {
|
|
3342
3520
|
window.sessionStorage.removeItem(key);
|
|
3343
|
-
window.sessionStorage.removeItem(`${key}
|
|
3521
|
+
window.sessionStorage.removeItem(`${key}_ts`);
|
|
3344
3522
|
} catch (retryError) {
|
|
3345
3523
|
authLogger.error(`Failed to remove sessionStorage key "${key}" after clearing:`, retryError);
|
|
3346
3524
|
forceClearAll();
|
|
@@ -3359,7 +3537,7 @@ function useSessionStorage(key, initialValue) {
|
|
|
3359
3537
|
__name(useSessionStorage, "useSessionStorage");
|
|
3360
3538
|
|
|
3361
3539
|
// src/auth/hooks/useAuthRedirect.ts
|
|
3362
|
-
var AUTH_REDIRECT_KEY =
|
|
3540
|
+
var AUTH_REDIRECT_KEY = CFG_KEYS.redirectUrl.key;
|
|
3363
3541
|
var getRedirectFromStorage = /* @__PURE__ */ __name(() => {
|
|
3364
3542
|
if (typeof window === "undefined") return "";
|
|
3365
3543
|
try {
|
|
@@ -3373,7 +3551,7 @@ var clearRedirectFromStorage = /* @__PURE__ */ __name(() => {
|
|
|
3373
3551
|
if (typeof window === "undefined") return;
|
|
3374
3552
|
try {
|
|
3375
3553
|
window.sessionStorage.removeItem(AUTH_REDIRECT_KEY);
|
|
3376
|
-
window.sessionStorage.removeItem(`${AUTH_REDIRECT_KEY}
|
|
3554
|
+
window.sessionStorage.removeItem(`${AUTH_REDIRECT_KEY}_ts`);
|
|
3377
3555
|
} catch {
|
|
3378
3556
|
}
|
|
3379
3557
|
}, "clearRedirectFromStorage");
|
|
@@ -3789,7 +3967,7 @@ function useLocalStorage(key, initialValue) {
|
|
|
3789
3967
|
const key2 = keys[i];
|
|
3790
3968
|
if (key2) {
|
|
3791
3969
|
localStorage.removeItem(key2);
|
|
3792
|
-
localStorage.removeItem(`${key2}
|
|
3970
|
+
localStorage.removeItem(`${key2}_ts`);
|
|
3793
3971
|
}
|
|
3794
3972
|
} catch {
|
|
3795
3973
|
}
|
|
@@ -3819,7 +3997,7 @@ function useLocalStorage(key, initialValue) {
|
|
|
3819
3997
|
authLogger.warn(`Data size too large for key "${key}", removing key`);
|
|
3820
3998
|
try {
|
|
3821
3999
|
window.localStorage.removeItem(key);
|
|
3822
|
-
window.localStorage.removeItem(`${key}
|
|
4000
|
+
window.localStorage.removeItem(`${key}_ts`);
|
|
3823
4001
|
} catch {
|
|
3824
4002
|
}
|
|
3825
4003
|
setStoredValue(valueToStore);
|
|
@@ -3833,7 +4011,7 @@ function useLocalStorage(key, initialValue) {
|
|
|
3833
4011
|
} else {
|
|
3834
4012
|
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
|
3835
4013
|
}
|
|
3836
|
-
window.localStorage.setItem(`${key}
|
|
4014
|
+
window.localStorage.setItem(`${key}_ts`, Date.now().toString());
|
|
3837
4015
|
} catch (storageError) {
|
|
3838
4016
|
if (isQuotaExceededError(storageError)) {
|
|
3839
4017
|
authLogger.warn("localStorage quota exceeded, clearing old data...");
|
|
@@ -3844,7 +4022,7 @@ function useLocalStorage(key, initialValue) {
|
|
|
3844
4022
|
} else {
|
|
3845
4023
|
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
|
3846
4024
|
}
|
|
3847
|
-
window.localStorage.setItem(`${key}
|
|
4025
|
+
window.localStorage.setItem(`${key}_ts`, Date.now().toString());
|
|
3848
4026
|
} catch (retryError) {
|
|
3849
4027
|
authLogger.error(`Failed to set localStorage key "${key}" after clearing old data:`, retryError);
|
|
3850
4028
|
try {
|
|
@@ -3854,7 +4032,7 @@ function useLocalStorage(key, initialValue) {
|
|
|
3854
4032
|
} else {
|
|
3855
4033
|
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
|
3856
4034
|
}
|
|
3857
|
-
window.localStorage.setItem(`${key}
|
|
4035
|
+
window.localStorage.setItem(`${key}_ts`, Date.now().toString());
|
|
3858
4036
|
} catch (finalError) {
|
|
3859
4037
|
authLogger.error(`Failed to set localStorage key "${key}" after force clearing:`, finalError);
|
|
3860
4038
|
setStoredValue(valueToStore);
|
|
@@ -3877,14 +4055,14 @@ function useLocalStorage(key, initialValue) {
|
|
|
3877
4055
|
if (typeof window !== "undefined") {
|
|
3878
4056
|
try {
|
|
3879
4057
|
window.localStorage.removeItem(key);
|
|
3880
|
-
window.localStorage.removeItem(`${key}
|
|
4058
|
+
window.localStorage.removeItem(`${key}_ts`);
|
|
3881
4059
|
} catch (removeError) {
|
|
3882
4060
|
if (isQuotaExceededError(removeError)) {
|
|
3883
4061
|
authLogger.warn("localStorage quota exceeded during removal, clearing old data...");
|
|
3884
4062
|
clearOldData();
|
|
3885
4063
|
try {
|
|
3886
4064
|
window.localStorage.removeItem(key);
|
|
3887
|
-
window.localStorage.removeItem(`${key}
|
|
4065
|
+
window.localStorage.removeItem(`${key}_ts`);
|
|
3888
4066
|
} catch (retryError) {
|
|
3889
4067
|
authLogger.error(`Failed to remove localStorage key "${key}" after clearing:`, retryError);
|
|
3890
4068
|
forceClearAll();
|
|
@@ -3952,7 +4130,7 @@ function useBase64() {
|
|
|
3952
4130
|
__name(useBase64, "useBase64");
|
|
3953
4131
|
|
|
3954
4132
|
// src/auth/hooks/useProfileCache.ts
|
|
3955
|
-
var CACHE_KEY =
|
|
4133
|
+
var CACHE_KEY = CFG_KEYS.profileCache.key;
|
|
3956
4134
|
var CACHE_VERSION = 1;
|
|
3957
4135
|
var DEFAULT_TTL = 144e5;
|
|
3958
4136
|
function getCachedProfile() {
|
|
@@ -4597,7 +4775,7 @@ var resolveAuthRoutes = /* @__PURE__ */ __name((routes) => ({
|
|
|
4597
4775
|
defaultCallback: routes?.defaultCallback || defaultRoutes.defaultCallback,
|
|
4598
4776
|
defaultAuthCallback: routes?.defaultAuthCallback || routes?.auth || defaultRoutes.defaultAuthCallback
|
|
4599
4777
|
}), "resolveAuthRoutes");
|
|
4600
|
-
var EMAIL_STORAGE_KEY =
|
|
4778
|
+
var EMAIL_STORAGE_KEY = CFG_KEYS.email.key;
|
|
4601
4779
|
var AuthContext = (0, import_react17.createContext)(void 0);
|
|
4602
4780
|
var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
4603
4781
|
const accounts = useAccountsContext();
|
|
@@ -4744,14 +4922,13 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4744
4922
|
[]
|
|
4745
4923
|
);
|
|
4746
4924
|
const verifyOTP = (0, import_react17.useCallback)(
|
|
4747
|
-
async (identifier, otpCode, sourceUrl, redirectUrl, skipRedirect
|
|
4925
|
+
async (identifier, otpCode, sourceUrl, redirectUrl, skipRedirect) => {
|
|
4748
4926
|
try {
|
|
4749
4927
|
pendingManualNavRef.current = Boolean(skipRedirect);
|
|
4750
4928
|
const result = await accountsRef.current.verifyOTP({
|
|
4751
4929
|
identifier,
|
|
4752
4930
|
otp: otpCode,
|
|
4753
|
-
source_url: sourceUrl
|
|
4754
|
-
remember_me: rememberMe
|
|
4931
|
+
source_url: sourceUrl
|
|
4755
4932
|
});
|
|
4756
4933
|
if (result.requires_2fa && result.session_id) {
|
|
4757
4934
|
authLogger.info("2FA required, session:", result.session_id);
|
|
@@ -4806,13 +4983,12 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4806
4983
|
);
|
|
4807
4984
|
const login = (0, import_react17.useCallback)(
|
|
4808
4985
|
async (email, password, options) => {
|
|
4809
|
-
const { redirectUrl, skipRedirect
|
|
4986
|
+
const { redirectUrl, skipRedirect } = options || {};
|
|
4810
4987
|
try {
|
|
4811
4988
|
pendingManualNavRef.current = Boolean(skipRedirect);
|
|
4812
4989
|
const result = await accountsRef.current.loginWithPassword({
|
|
4813
4990
|
email,
|
|
4814
|
-
password
|
|
4815
|
-
remember_me: rememberMe
|
|
4991
|
+
password
|
|
4816
4992
|
});
|
|
4817
4993
|
if (result.requires_2fa && result.session_id) {
|
|
4818
4994
|
authLogger.info("2FA required, session:", result.session_id);
|