@djangocfg/api 2.1.483 → 2.1.486
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 +51 -5
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.mjs +51 -5
- package/dist/auth.mjs.map +1 -1
- package/dist/clients.cjs +36 -5
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.mjs +36 -5
- package/dist/clients.mjs.map +1 -1
- package/dist/hooks.cjs +36 -5
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.mjs +36 -5
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.cjs +36 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +36 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/_api/generated/helpers/auth.ts +53 -9
- package/src/auth/context/AccountsContext.tsx +28 -0
package/dist/auth.cjs
CHANGED
|
@@ -228,8 +228,23 @@ var cookieBackend = {
|
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
};
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
function backendFor(mode) {
|
|
232
|
+
return mode === "cookie" ? cookieBackend : mode === "sessionStorage" ? sessionStorageBackend : localStorageBackend;
|
|
233
|
+
}
|
|
234
|
+
__name(backendFor, "backendFor");
|
|
235
|
+
var STORAGE_MODE_KEY = "cfg.access_token.storage_mode";
|
|
236
|
+
function readPersistedMode() {
|
|
237
|
+
if (!isBrowser) return "localStorage";
|
|
238
|
+
try {
|
|
239
|
+
const raw = window.localStorage.getItem(STORAGE_MODE_KEY);
|
|
240
|
+
return raw === "sessionStorage" || raw === "cookie" || raw === "localStorage" ? raw : "localStorage";
|
|
241
|
+
} catch {
|
|
242
|
+
return "localStorage";
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
__name(readPersistedMode, "readPersistedMode");
|
|
246
|
+
var _storageMode = readPersistedMode();
|
|
247
|
+
var _storage = backendFor(_storageMode);
|
|
233
248
|
function detectLocale() {
|
|
234
249
|
try {
|
|
235
250
|
if (typeof document !== "undefined") {
|
|
@@ -385,7 +400,13 @@ var auth = {
|
|
|
385
400
|
},
|
|
386
401
|
setStorageMode(mode) {
|
|
387
402
|
_storageMode = mode;
|
|
388
|
-
_storage = mode
|
|
403
|
+
_storage = backendFor(mode);
|
|
404
|
+
if (isBrowser) {
|
|
405
|
+
try {
|
|
406
|
+
window.localStorage.setItem(STORAGE_MODE_KEY, mode);
|
|
407
|
+
} catch {
|
|
408
|
+
}
|
|
409
|
+
}
|
|
389
410
|
notifySessionChanged();
|
|
390
411
|
},
|
|
391
412
|
// ── Bearer token ──────────────────────────────────────────────────
|
|
@@ -404,8 +425,18 @@ var auth = {
|
|
|
404
425
|
notifySessionChanged();
|
|
405
426
|
},
|
|
406
427
|
clearTokens() {
|
|
407
|
-
|
|
408
|
-
|
|
428
|
+
for (const backend of [localStorageBackend, sessionStorageBackend, cookieBackend]) {
|
|
429
|
+
backend.set(ACCESS_KEY, null);
|
|
430
|
+
backend.set(REFRESH_KEY, null);
|
|
431
|
+
}
|
|
432
|
+
_storageMode = "localStorage";
|
|
433
|
+
_storage = localStorageBackend;
|
|
434
|
+
if (isBrowser) {
|
|
435
|
+
try {
|
|
436
|
+
window.localStorage.removeItem(STORAGE_MODE_KEY);
|
|
437
|
+
} catch {
|
|
438
|
+
}
|
|
439
|
+
}
|
|
409
440
|
notifySessionChanged();
|
|
410
441
|
},
|
|
411
442
|
/** Session-aware: token PRESENT and not past its `exp` (or a live refresh
|
|
@@ -4416,6 +4447,17 @@ var TokenRefreshRequestSchema = import_zod34.z.object({
|
|
|
4416
4447
|
|
|
4417
4448
|
// src/auth/context/AccountsContext.tsx
|
|
4418
4449
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
4450
|
+
function hasApiOrigin() {
|
|
4451
|
+
try {
|
|
4452
|
+
if (typeof process === "undefined" || !process.env) return false;
|
|
4453
|
+
if (process.env.NEXT_PUBLIC_STATIC_BUILD === "true") return true;
|
|
4454
|
+
if (process.env.NEXT_PUBLIC_API_PROXY_URL !== void 0) return true;
|
|
4455
|
+
return Boolean(process.env.NEXT_PUBLIC_API_URL);
|
|
4456
|
+
} catch {
|
|
4457
|
+
return false;
|
|
4458
|
+
}
|
|
4459
|
+
}
|
|
4460
|
+
__name(hasApiOrigin, "hasApiOrigin");
|
|
4419
4461
|
var AccountsContext = (0, import_react15.createContext)(void 0);
|
|
4420
4462
|
function AccountsProvider({ children }) {
|
|
4421
4463
|
const [profile, setProfile] = (0, import_react15.useState)(() => {
|
|
@@ -4439,6 +4481,10 @@ function AccountsProvider({ children }) {
|
|
|
4439
4481
|
const { trigger: triggerOtpVerify } = useCfgAccountsOtpVerifyCreate();
|
|
4440
4482
|
const refreshProfile = (0, import_react15.useCallback)(async (options) => {
|
|
4441
4483
|
const { callerId, force } = options || {};
|
|
4484
|
+
if (!hasApiOrigin()) {
|
|
4485
|
+
authLogger.debug(`No API origin configured, skipping profile fetch (caller: ${callerId})`);
|
|
4486
|
+
return void 0;
|
|
4487
|
+
}
|
|
4442
4488
|
if (isLoadingRef.current) {
|
|
4443
4489
|
authLogger.debug(`Profile loading in progress, skipping (caller: ${callerId})`);
|
|
4444
4490
|
return profileRef.current;
|