@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.mjs
CHANGED
|
@@ -158,8 +158,23 @@ var cookieBackend = {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
};
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
function backendFor(mode) {
|
|
162
|
+
return mode === "cookie" ? cookieBackend : mode === "sessionStorage" ? sessionStorageBackend : localStorageBackend;
|
|
163
|
+
}
|
|
164
|
+
__name(backendFor, "backendFor");
|
|
165
|
+
var STORAGE_MODE_KEY = "cfg.access_token.storage_mode";
|
|
166
|
+
function readPersistedMode() {
|
|
167
|
+
if (!isBrowser) return "localStorage";
|
|
168
|
+
try {
|
|
169
|
+
const raw = window.localStorage.getItem(STORAGE_MODE_KEY);
|
|
170
|
+
return raw === "sessionStorage" || raw === "cookie" || raw === "localStorage" ? raw : "localStorage";
|
|
171
|
+
} catch {
|
|
172
|
+
return "localStorage";
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
__name(readPersistedMode, "readPersistedMode");
|
|
176
|
+
var _storageMode = readPersistedMode();
|
|
177
|
+
var _storage = backendFor(_storageMode);
|
|
163
178
|
function detectLocale() {
|
|
164
179
|
try {
|
|
165
180
|
if (typeof document !== "undefined") {
|
|
@@ -315,7 +330,13 @@ var auth = {
|
|
|
315
330
|
},
|
|
316
331
|
setStorageMode(mode) {
|
|
317
332
|
_storageMode = mode;
|
|
318
|
-
_storage = mode
|
|
333
|
+
_storage = backendFor(mode);
|
|
334
|
+
if (isBrowser) {
|
|
335
|
+
try {
|
|
336
|
+
window.localStorage.setItem(STORAGE_MODE_KEY, mode);
|
|
337
|
+
} catch {
|
|
338
|
+
}
|
|
339
|
+
}
|
|
319
340
|
notifySessionChanged();
|
|
320
341
|
},
|
|
321
342
|
// ── Bearer token ──────────────────────────────────────────────────
|
|
@@ -334,8 +355,18 @@ var auth = {
|
|
|
334
355
|
notifySessionChanged();
|
|
335
356
|
},
|
|
336
357
|
clearTokens() {
|
|
337
|
-
|
|
338
|
-
|
|
358
|
+
for (const backend of [localStorageBackend, sessionStorageBackend, cookieBackend]) {
|
|
359
|
+
backend.set(ACCESS_KEY, null);
|
|
360
|
+
backend.set(REFRESH_KEY, null);
|
|
361
|
+
}
|
|
362
|
+
_storageMode = "localStorage";
|
|
363
|
+
_storage = localStorageBackend;
|
|
364
|
+
if (isBrowser) {
|
|
365
|
+
try {
|
|
366
|
+
window.localStorage.removeItem(STORAGE_MODE_KEY);
|
|
367
|
+
} catch {
|
|
368
|
+
}
|
|
369
|
+
}
|
|
339
370
|
notifySessionChanged();
|
|
340
371
|
},
|
|
341
372
|
/** Session-aware: token PRESENT and not past its `exp` (or a live refresh
|
|
@@ -4354,6 +4385,17 @@ var TokenRefreshRequestSchema = z34.object({
|
|
|
4354
4385
|
|
|
4355
4386
|
// src/auth/context/AccountsContext.tsx
|
|
4356
4387
|
import { jsx } from "react/jsx-runtime";
|
|
4388
|
+
function hasApiOrigin() {
|
|
4389
|
+
try {
|
|
4390
|
+
if (typeof process === "undefined" || !process.env) return false;
|
|
4391
|
+
if (process.env.NEXT_PUBLIC_STATIC_BUILD === "true") return true;
|
|
4392
|
+
if (process.env.NEXT_PUBLIC_API_PROXY_URL !== void 0) return true;
|
|
4393
|
+
return Boolean(process.env.NEXT_PUBLIC_API_URL);
|
|
4394
|
+
} catch {
|
|
4395
|
+
return false;
|
|
4396
|
+
}
|
|
4397
|
+
}
|
|
4398
|
+
__name(hasApiOrigin, "hasApiOrigin");
|
|
4357
4399
|
var AccountsContext = createContext(void 0);
|
|
4358
4400
|
function AccountsProvider({ children }) {
|
|
4359
4401
|
const [profile, setProfile] = useState10(() => {
|
|
@@ -4377,6 +4419,10 @@ function AccountsProvider({ children }) {
|
|
|
4377
4419
|
const { trigger: triggerOtpVerify } = useCfgAccountsOtpVerifyCreate();
|
|
4378
4420
|
const refreshProfile = useCallback10(async (options) => {
|
|
4379
4421
|
const { callerId, force } = options || {};
|
|
4422
|
+
if (!hasApiOrigin()) {
|
|
4423
|
+
authLogger.debug(`No API origin configured, skipping profile fetch (caller: ${callerId})`);
|
|
4424
|
+
return void 0;
|
|
4425
|
+
}
|
|
4380
4426
|
if (isLoadingRef.current) {
|
|
4381
4427
|
authLogger.debug(`Profile loading in progress, skipping (caller: ${callerId})`);
|
|
4382
4428
|
return profileRef.current;
|