@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.mjs
CHANGED
|
@@ -92,77 +92,263 @@ var APIError = class extends Error {
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
// src/_api/generated/helpers/
|
|
96
|
-
var
|
|
97
|
-
var
|
|
98
|
-
var
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
95
|
+
// src/_api/generated/helpers/keys.ts
|
|
96
|
+
var k = /* @__PURE__ */ __name((key, store, personal) => ({ key, store, personal }), "k");
|
|
97
|
+
var f = /* @__PURE__ */ __name((prefix, store, personal) => ({ prefix, store, personal }), "f");
|
|
98
|
+
var CFG_KEYS = {
|
|
99
|
+
accessToken: k("cfg.auth.access_token", "local", true),
|
|
100
|
+
refreshToken: k("cfg.auth.refresh_token", "local", true),
|
|
101
|
+
apiKey: k("cfg.auth.api_key", "local", true),
|
|
102
|
+
email: k("cfg.auth.email", "local", false),
|
|
103
|
+
emailTs: k("cfg.auth.email_ts", "local", false),
|
|
104
|
+
redirectUrl: k("cfg.auth.redirect_url", "session", true),
|
|
105
|
+
redirectUrlTs: k("cfg.auth.redirect_url_ts", "session", true),
|
|
106
|
+
oauthState: k("cfg.auth.oauth_state", "session", true),
|
|
107
|
+
oauthProvider: k("cfg.auth.oauth_provider", "session", true),
|
|
108
|
+
profileCache: k("cfg.profile.cache", "local", true),
|
|
109
|
+
monitorSessionId: k("cfg.monitor.session_id", "local", false),
|
|
110
|
+
monitorSessionCookie: k("cfg.monitor.session_id", "cookie", false),
|
|
111
|
+
monitorDebug: k("cfg.monitor.debug", "local", false),
|
|
112
|
+
uiTabId: k("cfg.ui.tab_id", "session", false),
|
|
113
|
+
uiRouterSerial: k("cfg.ui.router_serial", "session", false),
|
|
114
|
+
uiState: k("cfg.ui.state", "local", false),
|
|
115
|
+
chatSpeechLanguage: k("cfg.chat.speech_language", "local", false),
|
|
116
|
+
chatRecentTools: k("cfg.chat.recent_tools", "local", false),
|
|
117
|
+
formsSpeechDebug: k("cfg.forms.speech_debug", "local", false),
|
|
118
|
+
formsSpeechPrefs: k("cfg.forms.speech_prefs", "local", false),
|
|
119
|
+
agentPlaygroundApiKeyId: k("cfg.agent.playground_api_key_id", "session", true),
|
|
120
|
+
agentPlaygroundBearer: k("cfg.agent.playground_bearer", "session", true),
|
|
121
|
+
agentEndpointDoc: k("cfg.agent.endpoint_doc", "session", false)
|
|
122
|
+
};
|
|
123
|
+
var CFG_FAMILIES = {
|
|
124
|
+
chatDraft: f("cfg.chat.draft.", "session", true),
|
|
125
|
+
dataTree: f("cfg.data.tree.", "local", false),
|
|
126
|
+
agentEndpointDraft: f("cfg.agent.endpoint_draft.", "local", false)
|
|
127
|
+
};
|
|
128
|
+
var OWNER_RE = /^[a-z][a-z0-9_]*$/;
|
|
129
|
+
function normalizeSegment(raw) {
|
|
130
|
+
return raw.trim().toLowerCase().replace(/[^a-z0-9_]+/g, "_").replace(/^_+|_+$/g, "");
|
|
131
|
+
}
|
|
132
|
+
__name(normalizeSegment, "normalizeSegment");
|
|
133
|
+
var hasWindow = /* @__PURE__ */ __name(() => typeof window !== "undefined", "hasWindow");
|
|
134
|
+
function nativeStorage(store) {
|
|
135
|
+
if (!hasWindow()) return null;
|
|
136
|
+
try {
|
|
137
|
+
return store === "session" ? window.sessionStorage : window.localStorage;
|
|
138
|
+
} catch {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
__name(nativeStorage, "nativeStorage");
|
|
143
|
+
function cookieNames() {
|
|
144
|
+
if (!hasWindow()) return [];
|
|
145
|
+
try {
|
|
146
|
+
return document.cookie.split("; ").map((part) => decodeURIComponent(part.split("=")[0] ?? "")).filter(Boolean);
|
|
147
|
+
} catch {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
__name(cookieNames, "cookieNames");
|
|
152
|
+
function createStorage(owner, options = {}) {
|
|
153
|
+
if (!OWNER_RE.test(owner)) {
|
|
154
|
+
throw new TypeError(`createStorage: owner "${owner}" must match ${OWNER_RE}`);
|
|
155
|
+
}
|
|
156
|
+
const prefix = `${owner}.`;
|
|
157
|
+
const pattern = owner === "cfg" ? /^cfg(\.[a-z0-9_]+)+$/ : new RegExp(`^(cfg|${owner})(\\.[a-z0-9_]+)+$`);
|
|
158
|
+
const cookieMaxAge = options.cookieMaxAgeSeconds ?? 60 * 60 * 24 * 30;
|
|
159
|
+
const specs = Object.values(options.keys ?? {});
|
|
160
|
+
const families = Object.values(options.families ?? {});
|
|
161
|
+
const specByKey = /* @__PURE__ */ new Map();
|
|
162
|
+
for (const spec of specs) specByKey.set(spec.key, [...specByKey.get(spec.key) ?? [], spec]);
|
|
163
|
+
const memory = {
|
|
164
|
+
local: /* @__PURE__ */ new Map(),
|
|
165
|
+
session: /* @__PURE__ */ new Map(),
|
|
166
|
+
cookie: /* @__PURE__ */ new Map()
|
|
167
|
+
};
|
|
168
|
+
const isValid = /* @__PURE__ */ __name((key) => pattern.test(key), "isValid");
|
|
169
|
+
const assertValid = /* @__PURE__ */ __name((key) => {
|
|
170
|
+
if (!isValid(key)) throw new TypeError(`storage key "${key}" must match ${pattern}`);
|
|
171
|
+
}, "assertValid");
|
|
172
|
+
const assertOwned = /* @__PURE__ */ __name((key) => {
|
|
173
|
+
assertValid(key);
|
|
174
|
+
if (!key.startsWith(prefix)) throw new TypeError(`storage key "${key}" is not owned by "${owner}"`);
|
|
175
|
+
}, "assertOwned");
|
|
176
|
+
function rawGet(store, key) {
|
|
177
|
+
if (!hasWindow()) return null;
|
|
178
|
+
if (store === "cookie") {
|
|
179
|
+
try {
|
|
180
|
+
const escaped = encodeURIComponent(key).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
181
|
+
const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${escaped}=([^;]*)`));
|
|
182
|
+
if (match?.[1] !== void 0) return decodeURIComponent(match[1]);
|
|
183
|
+
} catch {
|
|
184
|
+
}
|
|
185
|
+
return memory.cookie.get(key) ?? null;
|
|
107
186
|
}
|
|
108
|
-
},
|
|
109
|
-
set(key, value) {
|
|
110
|
-
if (!isBrowser) return;
|
|
111
187
|
try {
|
|
112
|
-
|
|
113
|
-
|
|
188
|
+
const value = nativeStorage(store)?.getItem(key) ?? null;
|
|
189
|
+
if (value !== null) return value;
|
|
114
190
|
} catch {
|
|
115
191
|
}
|
|
192
|
+
return memory[store].get(key) ?? null;
|
|
116
193
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (!isBrowser) return null;
|
|
194
|
+
__name(rawGet, "rawGet");
|
|
195
|
+
function rawSet(store, key, value) {
|
|
196
|
+
if (!hasWindow()) return false;
|
|
121
197
|
try {
|
|
122
|
-
|
|
198
|
+
if (store === "cookie") {
|
|
199
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
200
|
+
document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)}; Path=/; Max-Age=${cookieMaxAge}; SameSite=Lax${secure}`;
|
|
201
|
+
if (rawGet("cookie", key) === value && !memory.cookie.has(key)) return true;
|
|
202
|
+
memory.cookie.set(key, value);
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
const native = nativeStorage(store);
|
|
206
|
+
if (!native) throw new Error("storage unavailable");
|
|
207
|
+
native.setItem(key, value);
|
|
208
|
+
memory[store].delete(key);
|
|
209
|
+
return true;
|
|
123
210
|
} catch {
|
|
124
|
-
|
|
211
|
+
memory[store].set(key, value);
|
|
212
|
+
return false;
|
|
125
213
|
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
214
|
+
}
|
|
215
|
+
__name(rawSet, "rawSet");
|
|
216
|
+
function rawRemove(store, key) {
|
|
217
|
+
memory[store].delete(key);
|
|
218
|
+
if (!hasWindow()) return;
|
|
129
219
|
try {
|
|
130
|
-
if (
|
|
131
|
-
|
|
220
|
+
if (store === "cookie") {
|
|
221
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
222
|
+
document.cookie = `${encodeURIComponent(key)}=; Path=/; Max-Age=0; SameSite=Lax${secure}`;
|
|
223
|
+
} else {
|
|
224
|
+
nativeStorage(store)?.removeItem(key);
|
|
225
|
+
}
|
|
132
226
|
} catch {
|
|
133
227
|
}
|
|
134
228
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
229
|
+
__name(rawRemove, "rawRemove");
|
|
230
|
+
function resolveStore(key, store) {
|
|
231
|
+
return store ?? specByKey.get(key)?.[0]?.store ?? "local";
|
|
232
|
+
}
|
|
233
|
+
__name(resolveStore, "resolveStore");
|
|
234
|
+
function listKeys(store, startsWith) {
|
|
235
|
+
const out = [];
|
|
140
236
|
try {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
237
|
+
const native = nativeStorage(store);
|
|
238
|
+
if (native) {
|
|
239
|
+
for (let i = 0; i < native.length; i += 1) {
|
|
240
|
+
const name = native.key(i);
|
|
241
|
+
if (name?.startsWith(startsWith)) out.push(name);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
145
244
|
} catch {
|
|
146
|
-
return null;
|
|
147
245
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
246
|
+
for (const name of memory[store].keys()) if (name.startsWith(startsWith) && !out.includes(name)) out.push(name);
|
|
247
|
+
return out;
|
|
248
|
+
}
|
|
249
|
+
__name(listKeys, "listKeys");
|
|
250
|
+
const familyKey = /* @__PURE__ */ __name((family, id) => {
|
|
251
|
+
const part = normalizeSegment(id);
|
|
252
|
+
if (!part) throw new TypeError("storage family id is empty after normalisation");
|
|
253
|
+
return family.prefix + part;
|
|
254
|
+
}, "familyKey");
|
|
255
|
+
const api = {
|
|
256
|
+
owner,
|
|
257
|
+
key(...parts) {
|
|
258
|
+
const segments = parts.map(normalizeSegment);
|
|
259
|
+
if (segments.length === 0 || segments.some((segment) => !segment)) {
|
|
260
|
+
throw new TypeError(`storage key parts must be non-empty: ${JSON.stringify(parts)}`);
|
|
159
261
|
}
|
|
160
|
-
|
|
262
|
+
return `${prefix}${segments.join(".")}`;
|
|
263
|
+
},
|
|
264
|
+
familyKey,
|
|
265
|
+
isValid,
|
|
266
|
+
read(key, store) {
|
|
267
|
+
assertValid(key);
|
|
268
|
+
const target = resolveStore(key, store);
|
|
269
|
+
return rawGet(target, key);
|
|
270
|
+
},
|
|
271
|
+
write(key, value, store) {
|
|
272
|
+
assertOwned(key);
|
|
273
|
+
const target = resolveStore(key, store);
|
|
274
|
+
return rawSet(target, key, value);
|
|
275
|
+
},
|
|
276
|
+
remove(key, store) {
|
|
277
|
+
assertOwned(key);
|
|
278
|
+
const target = resolveStore(key, store);
|
|
279
|
+
rawRemove(target, key);
|
|
280
|
+
},
|
|
281
|
+
readJSON(key, store) {
|
|
282
|
+
const raw = api.read(key, store);
|
|
283
|
+
if (raw === null) return null;
|
|
284
|
+
try {
|
|
285
|
+
return JSON.parse(raw);
|
|
286
|
+
} catch {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
writeJSON(key, value, store) {
|
|
291
|
+
return api.write(key, JSON.stringify(value), store);
|
|
292
|
+
},
|
|
293
|
+
keys(store = "local") {
|
|
294
|
+
return listKeys(store, prefix);
|
|
295
|
+
},
|
|
296
|
+
clearAll({ all = false } = {}) {
|
|
297
|
+
for (const spec of specs) {
|
|
298
|
+
if (!all && !spec.personal) continue;
|
|
299
|
+
rawRemove(spec.store, spec.key);
|
|
300
|
+
}
|
|
301
|
+
for (const family of families) {
|
|
302
|
+
if (!all && !family.personal) continue;
|
|
303
|
+
for (const name of listKeys(family.store, family.prefix)) rawRemove(family.store, name);
|
|
304
|
+
}
|
|
305
|
+
if (all) {
|
|
306
|
+
for (const store of ["local", "session"]) {
|
|
307
|
+
for (const name of listKeys(store, prefix)) rawRemove(store, name);
|
|
308
|
+
}
|
|
309
|
+
for (const name of cookieNames()) if (name.startsWith(prefix)) rawRemove("cookie", name);
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
onChange(key, listener, store = "local") {
|
|
313
|
+
assertValid(key);
|
|
314
|
+
if (!hasWindow()) return () => {
|
|
315
|
+
};
|
|
316
|
+
const handler = /* @__PURE__ */ __name((event) => {
|
|
317
|
+
if (event.storageArea !== nativeStorage(store)) return;
|
|
318
|
+
if (event.key === null || event.key === key) listener(event.key === null ? null : event.newValue);
|
|
319
|
+
}, "handler");
|
|
320
|
+
window.addEventListener("storage", handler);
|
|
321
|
+
return () => window.removeEventListener("storage", handler);
|
|
161
322
|
}
|
|
162
|
-
}
|
|
323
|
+
};
|
|
324
|
+
return api;
|
|
325
|
+
}
|
|
326
|
+
__name(createStorage, "createStorage");
|
|
327
|
+
var cfgStorage = createStorage("cfg", {
|
|
328
|
+
keys: CFG_KEYS,
|
|
329
|
+
families: CFG_FAMILIES
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// src/_api/generated/helpers/auth.ts
|
|
333
|
+
var ACCESS_KEY = "cfg.auth.access_token";
|
|
334
|
+
var REFRESH_KEY = "cfg.auth.refresh_token";
|
|
335
|
+
var API_KEY_KEY = "cfg.auth.api_key";
|
|
336
|
+
var storage = true ? cfgStorage : createStorage2("cfg");
|
|
337
|
+
var isBrowser = typeof window !== "undefined";
|
|
338
|
+
var STORE_OF = {
|
|
339
|
+
localStorage: "local",
|
|
340
|
+
sessionStorage: "session",
|
|
341
|
+
cookie: "cookie"
|
|
163
342
|
};
|
|
164
343
|
function backendFor(mode) {
|
|
165
|
-
|
|
344
|
+
const store = STORE_OF[mode];
|
|
345
|
+
return {
|
|
346
|
+
get: /* @__PURE__ */ __name((key) => storage.read(key, store), "get"),
|
|
347
|
+
set(key, value) {
|
|
348
|
+
if (value === null) storage.remove(key, store);
|
|
349
|
+
else storage.write(key, value, store);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
166
352
|
}
|
|
167
353
|
__name(backendFor, "backendFor");
|
|
168
354
|
var _storageMode = "localStorage";
|
|
@@ -351,10 +537,12 @@ var auth = {
|
|
|
351
537
|
notifySessionChanged();
|
|
352
538
|
},
|
|
353
539
|
clearTokens() {
|
|
354
|
-
for (const
|
|
540
|
+
for (const mode of ["localStorage", "sessionStorage", "cookie"]) {
|
|
541
|
+
const backend = backendFor(mode);
|
|
355
542
|
backend.set(ACCESS_KEY, null);
|
|
356
543
|
backend.set(REFRESH_KEY, null);
|
|
357
544
|
}
|
|
545
|
+
storage.clearAll();
|
|
358
546
|
notifySessionChanged();
|
|
359
547
|
},
|
|
360
548
|
/** Session-aware: token PRESENT and not past its `exp` (or a live refresh
|
|
@@ -546,7 +734,7 @@ function dpopEnabled() {
|
|
|
546
734
|
}
|
|
547
735
|
}
|
|
548
736
|
__name(dpopEnabled, "dpopEnabled");
|
|
549
|
-
var _DPOP_DB = "cfg
|
|
737
|
+
var _DPOP_DB = "cfg.auth.dpop";
|
|
550
738
|
var _DPOP_STORE = "keys";
|
|
551
739
|
var _DPOP_KEY_ID = "dpop-ec-p256";
|
|
552
740
|
function _idbOpen() {
|
|
@@ -1009,7 +1197,6 @@ var useAuthFormState = /* @__PURE__ */ __name((initialIdentifier = "") => {
|
|
|
1009
1197
|
const [isLoading, setIsLoading] = useState2(false);
|
|
1010
1198
|
const [acceptedTerms, setAcceptedTerms] = useState2(true);
|
|
1011
1199
|
const [marketingConsent, setMarketingConsent] = useState2(null);
|
|
1012
|
-
const [rememberMe, setRememberMe] = useState2(true);
|
|
1013
1200
|
const [step, setStep] = useState2("identifier");
|
|
1014
1201
|
const [error, setError] = useState2("");
|
|
1015
1202
|
const [webmail, setWebmail] = useState2(null);
|
|
@@ -1024,7 +1211,6 @@ var useAuthFormState = /* @__PURE__ */ __name((initialIdentifier = "") => {
|
|
|
1024
1211
|
isLoading,
|
|
1025
1212
|
acceptedTerms,
|
|
1026
1213
|
marketingConsent,
|
|
1027
|
-
rememberMe,
|
|
1028
1214
|
step,
|
|
1029
1215
|
error,
|
|
1030
1216
|
rateLimitSeconds: rateLimit.seconds,
|
|
@@ -1039,7 +1225,6 @@ var useAuthFormState = /* @__PURE__ */ __name((initialIdentifier = "") => {
|
|
|
1039
1225
|
setPassword,
|
|
1040
1226
|
setAcceptedTerms,
|
|
1041
1227
|
setMarketingConsent,
|
|
1042
|
-
setRememberMe,
|
|
1043
1228
|
setError,
|
|
1044
1229
|
clearError,
|
|
1045
1230
|
setStep,
|
|
@@ -1174,7 +1359,6 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1174
1359
|
password,
|
|
1175
1360
|
acceptedTerms,
|
|
1176
1361
|
marketingConsent,
|
|
1177
|
-
rememberMe,
|
|
1178
1362
|
setIdentifier,
|
|
1179
1363
|
setOtp,
|
|
1180
1364
|
setStep,
|
|
@@ -1271,7 +1455,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1271
1455
|
setIsLoading(true);
|
|
1272
1456
|
clearError();
|
|
1273
1457
|
try {
|
|
1274
|
-
const result = await verifyOTP(submitIdentifier, submitOtp, sourceUrl, redirectUrl, true
|
|
1458
|
+
const result = await verifyOTP(submitIdentifier, submitOtp, sourceUrl, redirectUrl, true);
|
|
1275
1459
|
if (result.requires_2fa && result.session_id) {
|
|
1276
1460
|
authLogger.info("2FA required after OTP verification");
|
|
1277
1461
|
beginTwoFactorChallenge({ sessionId: result.session_id });
|
|
@@ -1297,7 +1481,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1297
1481
|
} finally {
|
|
1298
1482
|
setIsLoading(false);
|
|
1299
1483
|
}
|
|
1300
|
-
}, [verifyOTP, saveIdentifierToStorage, setError, setIsLoading, clearError, onOTPSuccess, onError, sourceUrl, redirectUrl,
|
|
1484
|
+
}, [verifyOTP, saveIdentifierToStorage, setError, setIsLoading, clearError, onOTPSuccess, onError, sourceUrl, redirectUrl, setStep]);
|
|
1301
1485
|
const handleOTPSubmit = useCallback4(async (e) => {
|
|
1302
1486
|
e.preventDefault();
|
|
1303
1487
|
await submitOTP(identifier, otp);
|
|
@@ -1320,8 +1504,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1320
1504
|
try {
|
|
1321
1505
|
const result = await login(submitIdentifier, submitPassword_, {
|
|
1322
1506
|
redirectUrl,
|
|
1323
|
-
skipRedirect: true
|
|
1324
|
-
rememberMe
|
|
1507
|
+
skipRedirect: true
|
|
1325
1508
|
});
|
|
1326
1509
|
if (result.requires_2fa && result.session_id) {
|
|
1327
1510
|
authLogger.info("2FA required after password login");
|
|
@@ -1363,7 +1546,6 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
1363
1546
|
onOTPSuccess,
|
|
1364
1547
|
onError,
|
|
1365
1548
|
redirectUrl,
|
|
1366
|
-
rememberMe,
|
|
1367
1549
|
setStep
|
|
1368
1550
|
]);
|
|
1369
1551
|
const handlePasswordSubmit = useCallback4(async (e) => {
|
|
@@ -2881,8 +3063,10 @@ var logAuthFailure = /* @__PURE__ */ __name((log, message, error) => {
|
|
|
2881
3063
|
}, "logAuthFailure");
|
|
2882
3064
|
|
|
2883
3065
|
// src/auth/hooks/useGithubAuth.ts
|
|
3066
|
+
var OAUTH_STATE_KEY = CFG_KEYS.oauthState.key;
|
|
3067
|
+
var OAUTH_PROVIDER_KEY = CFG_KEYS.oauthProvider.key;
|
|
2884
3068
|
var useGithubAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
2885
|
-
const { sourceUrl,
|
|
3069
|
+
const { sourceUrl, onSuccess, onError, onRequires2FA, redirectUrl, skipRedirect = false } = options;
|
|
2886
3070
|
const router = useCfgRouter();
|
|
2887
3071
|
const [isLoading, setIsLoading] = useState3(false);
|
|
2888
3072
|
const [error, setError] = useState3(null);
|
|
@@ -2908,9 +3092,8 @@ var useGithubAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
|
2908
3092
|
}
|
|
2909
3093
|
authLogger.info("Redirecting to GitHub...", response.authorization_url);
|
|
2910
3094
|
if (typeof window !== "undefined") {
|
|
2911
|
-
sessionStorage.setItem(
|
|
2912
|
-
sessionStorage.setItem(
|
|
2913
|
-
sessionStorage.setItem("cfg.oauth.remember_me", String(rememberMe));
|
|
3095
|
+
sessionStorage.setItem(OAUTH_STATE_KEY, response.state);
|
|
3096
|
+
sessionStorage.setItem(OAUTH_PROVIDER_KEY, "github");
|
|
2914
3097
|
}
|
|
2915
3098
|
window.location.href = response.authorization_url;
|
|
2916
3099
|
} catch (err) {
|
|
@@ -2925,25 +3108,22 @@ var useGithubAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
|
2925
3108
|
} finally {
|
|
2926
3109
|
setIsLoading(false);
|
|
2927
3110
|
}
|
|
2928
|
-
}, [sourceUrl,
|
|
3111
|
+
}, [sourceUrl, onError]);
|
|
2929
3112
|
const handleGithubCallback = useCallback5(async (code, state) => {
|
|
2930
3113
|
setIsLoading(true);
|
|
2931
3114
|
setError(null);
|
|
2932
3115
|
try {
|
|
2933
3116
|
authLogger.info("Processing GitHub OAuth callback...");
|
|
2934
|
-
let rememberMeForSession = false;
|
|
2935
3117
|
if (typeof window !== "undefined") {
|
|
2936
|
-
const storedState = sessionStorage.getItem(
|
|
3118
|
+
const storedState = sessionStorage.getItem(OAUTH_STATE_KEY);
|
|
2937
3119
|
if (storedState && storedState !== state) {
|
|
2938
3120
|
throw new Error("Invalid OAuth state - possible CSRF attack");
|
|
2939
3121
|
}
|
|
2940
|
-
|
|
2941
|
-
sessionStorage.removeItem(
|
|
2942
|
-
sessionStorage.removeItem("oauth_provider");
|
|
2943
|
-
sessionStorage.removeItem("cfg.oauth.remember_me");
|
|
3122
|
+
sessionStorage.removeItem(OAUTH_STATE_KEY);
|
|
3123
|
+
sessionStorage.removeItem(OAUTH_PROVIDER_KEY);
|
|
2944
3124
|
}
|
|
2945
3125
|
const result = await CfgAccountsOauth.cfgAccountsOauthGithubCallbackCreate({
|
|
2946
|
-
body: { code, state
|
|
3126
|
+
body: { code, state },
|
|
2947
3127
|
throwOnError: true
|
|
2948
3128
|
});
|
|
2949
3129
|
const response = result.data;
|
|
@@ -3052,7 +3232,7 @@ function useSessionStorage(key, initialValue) {
|
|
|
3052
3232
|
const key2 = keys[i];
|
|
3053
3233
|
if (key2) {
|
|
3054
3234
|
sessionStorage.removeItem(key2);
|
|
3055
|
-
sessionStorage.removeItem(`${key2}
|
|
3235
|
+
sessionStorage.removeItem(`${key2}_ts`);
|
|
3056
3236
|
}
|
|
3057
3237
|
} catch {
|
|
3058
3238
|
}
|
|
@@ -3082,7 +3262,7 @@ function useSessionStorage(key, initialValue) {
|
|
|
3082
3262
|
authLogger.warn(`Data size too large for key "${key}", removing key`);
|
|
3083
3263
|
try {
|
|
3084
3264
|
window.sessionStorage.removeItem(key);
|
|
3085
|
-
window.sessionStorage.removeItem(`${key}
|
|
3265
|
+
window.sessionStorage.removeItem(`${key}_ts`);
|
|
3086
3266
|
} catch {
|
|
3087
3267
|
}
|
|
3088
3268
|
setStoredValue(valueToStore);
|
|
@@ -3092,20 +3272,20 @@ function useSessionStorage(key, initialValue) {
|
|
|
3092
3272
|
if (typeof window !== "undefined") {
|
|
3093
3273
|
try {
|
|
3094
3274
|
window.sessionStorage.setItem(key, JSON.stringify(valueToStore));
|
|
3095
|
-
window.sessionStorage.setItem(`${key}
|
|
3275
|
+
window.sessionStorage.setItem(`${key}_ts`, Date.now().toString());
|
|
3096
3276
|
} catch (storageError) {
|
|
3097
3277
|
if (isQuotaExceededError(storageError)) {
|
|
3098
3278
|
authLogger.warn("sessionStorage quota exceeded, clearing old data...");
|
|
3099
3279
|
clearOldData();
|
|
3100
3280
|
try {
|
|
3101
3281
|
window.sessionStorage.setItem(key, JSON.stringify(valueToStore));
|
|
3102
|
-
window.sessionStorage.setItem(`${key}
|
|
3282
|
+
window.sessionStorage.setItem(`${key}_ts`, Date.now().toString());
|
|
3103
3283
|
} catch (retryError) {
|
|
3104
3284
|
authLogger.error(`Failed to set sessionStorage key "${key}" after clearing old data:`, retryError);
|
|
3105
3285
|
try {
|
|
3106
3286
|
forceClearAll();
|
|
3107
3287
|
window.sessionStorage.setItem(key, JSON.stringify(valueToStore));
|
|
3108
|
-
window.sessionStorage.setItem(`${key}
|
|
3288
|
+
window.sessionStorage.setItem(`${key}_ts`, Date.now().toString());
|
|
3109
3289
|
} catch (finalError) {
|
|
3110
3290
|
authLogger.error(`Failed to set sessionStorage key "${key}" after force clearing:`, finalError);
|
|
3111
3291
|
setStoredValue(valueToStore);
|
|
@@ -3128,14 +3308,14 @@ function useSessionStorage(key, initialValue) {
|
|
|
3128
3308
|
if (typeof window !== "undefined") {
|
|
3129
3309
|
try {
|
|
3130
3310
|
window.sessionStorage.removeItem(key);
|
|
3131
|
-
window.sessionStorage.removeItem(`${key}
|
|
3311
|
+
window.sessionStorage.removeItem(`${key}_ts`);
|
|
3132
3312
|
} catch (removeError) {
|
|
3133
3313
|
if (isQuotaExceededError(removeError)) {
|
|
3134
3314
|
authLogger.warn("sessionStorage quota exceeded during removal, clearing old data...");
|
|
3135
3315
|
clearOldData();
|
|
3136
3316
|
try {
|
|
3137
3317
|
window.sessionStorage.removeItem(key);
|
|
3138
|
-
window.sessionStorage.removeItem(`${key}
|
|
3318
|
+
window.sessionStorage.removeItem(`${key}_ts`);
|
|
3139
3319
|
} catch (retryError) {
|
|
3140
3320
|
authLogger.error(`Failed to remove sessionStorage key "${key}" after clearing:`, retryError);
|
|
3141
3321
|
forceClearAll();
|
|
@@ -3154,7 +3334,7 @@ function useSessionStorage(key, initialValue) {
|
|
|
3154
3334
|
__name(useSessionStorage, "useSessionStorage");
|
|
3155
3335
|
|
|
3156
3336
|
// src/auth/hooks/useAuthRedirect.ts
|
|
3157
|
-
var AUTH_REDIRECT_KEY =
|
|
3337
|
+
var AUTH_REDIRECT_KEY = CFG_KEYS.redirectUrl.key;
|
|
3158
3338
|
var getRedirectFromStorage = /* @__PURE__ */ __name(() => {
|
|
3159
3339
|
if (typeof window === "undefined") return "";
|
|
3160
3340
|
try {
|
|
@@ -3168,7 +3348,7 @@ var clearRedirectFromStorage = /* @__PURE__ */ __name(() => {
|
|
|
3168
3348
|
if (typeof window === "undefined") return;
|
|
3169
3349
|
try {
|
|
3170
3350
|
window.sessionStorage.removeItem(AUTH_REDIRECT_KEY);
|
|
3171
|
-
window.sessionStorage.removeItem(`${AUTH_REDIRECT_KEY}
|
|
3351
|
+
window.sessionStorage.removeItem(`${AUTH_REDIRECT_KEY}_ts`);
|
|
3172
3352
|
} catch {
|
|
3173
3353
|
}
|
|
3174
3354
|
}, "clearRedirectFromStorage");
|
|
@@ -3584,7 +3764,7 @@ function useLocalStorage(key, initialValue) {
|
|
|
3584
3764
|
const key2 = keys[i];
|
|
3585
3765
|
if (key2) {
|
|
3586
3766
|
localStorage.removeItem(key2);
|
|
3587
|
-
localStorage.removeItem(`${key2}
|
|
3767
|
+
localStorage.removeItem(`${key2}_ts`);
|
|
3588
3768
|
}
|
|
3589
3769
|
} catch {
|
|
3590
3770
|
}
|
|
@@ -3614,7 +3794,7 @@ function useLocalStorage(key, initialValue) {
|
|
|
3614
3794
|
authLogger.warn(`Data size too large for key "${key}", removing key`);
|
|
3615
3795
|
try {
|
|
3616
3796
|
window.localStorage.removeItem(key);
|
|
3617
|
-
window.localStorage.removeItem(`${key}
|
|
3797
|
+
window.localStorage.removeItem(`${key}_ts`);
|
|
3618
3798
|
} catch {
|
|
3619
3799
|
}
|
|
3620
3800
|
setStoredValue(valueToStore);
|
|
@@ -3628,7 +3808,7 @@ function useLocalStorage(key, initialValue) {
|
|
|
3628
3808
|
} else {
|
|
3629
3809
|
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
|
3630
3810
|
}
|
|
3631
|
-
window.localStorage.setItem(`${key}
|
|
3811
|
+
window.localStorage.setItem(`${key}_ts`, Date.now().toString());
|
|
3632
3812
|
} catch (storageError) {
|
|
3633
3813
|
if (isQuotaExceededError(storageError)) {
|
|
3634
3814
|
authLogger.warn("localStorage quota exceeded, clearing old data...");
|
|
@@ -3639,7 +3819,7 @@ function useLocalStorage(key, initialValue) {
|
|
|
3639
3819
|
} else {
|
|
3640
3820
|
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
|
3641
3821
|
}
|
|
3642
|
-
window.localStorage.setItem(`${key}
|
|
3822
|
+
window.localStorage.setItem(`${key}_ts`, Date.now().toString());
|
|
3643
3823
|
} catch (retryError) {
|
|
3644
3824
|
authLogger.error(`Failed to set localStorage key "${key}" after clearing old data:`, retryError);
|
|
3645
3825
|
try {
|
|
@@ -3649,7 +3829,7 @@ function useLocalStorage(key, initialValue) {
|
|
|
3649
3829
|
} else {
|
|
3650
3830
|
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
|
3651
3831
|
}
|
|
3652
|
-
window.localStorage.setItem(`${key}
|
|
3832
|
+
window.localStorage.setItem(`${key}_ts`, Date.now().toString());
|
|
3653
3833
|
} catch (finalError) {
|
|
3654
3834
|
authLogger.error(`Failed to set localStorage key "${key}" after force clearing:`, finalError);
|
|
3655
3835
|
setStoredValue(valueToStore);
|
|
@@ -3672,14 +3852,14 @@ function useLocalStorage(key, initialValue) {
|
|
|
3672
3852
|
if (typeof window !== "undefined") {
|
|
3673
3853
|
try {
|
|
3674
3854
|
window.localStorage.removeItem(key);
|
|
3675
|
-
window.localStorage.removeItem(`${key}
|
|
3855
|
+
window.localStorage.removeItem(`${key}_ts`);
|
|
3676
3856
|
} catch (removeError) {
|
|
3677
3857
|
if (isQuotaExceededError(removeError)) {
|
|
3678
3858
|
authLogger.warn("localStorage quota exceeded during removal, clearing old data...");
|
|
3679
3859
|
clearOldData();
|
|
3680
3860
|
try {
|
|
3681
3861
|
window.localStorage.removeItem(key);
|
|
3682
|
-
window.localStorage.removeItem(`${key}
|
|
3862
|
+
window.localStorage.removeItem(`${key}_ts`);
|
|
3683
3863
|
} catch (retryError) {
|
|
3684
3864
|
authLogger.error(`Failed to remove localStorage key "${key}" after clearing:`, retryError);
|
|
3685
3865
|
forceClearAll();
|
|
@@ -3747,7 +3927,7 @@ function useBase64() {
|
|
|
3747
3927
|
__name(useBase64, "useBase64");
|
|
3748
3928
|
|
|
3749
3929
|
// src/auth/hooks/useProfileCache.ts
|
|
3750
|
-
var CACHE_KEY =
|
|
3930
|
+
var CACHE_KEY = CFG_KEYS.profileCache.key;
|
|
3751
3931
|
var CACHE_VERSION = 1;
|
|
3752
3932
|
var DEFAULT_TTL = 144e5;
|
|
3753
3933
|
function getCachedProfile() {
|
|
@@ -3971,7 +4151,7 @@ function useCfgAccountsOtpVerifyCreate(config) {
|
|
|
3971
4151
|
async (_key, { arg }) => {
|
|
3972
4152
|
const res = await CfgAccountsOtp.cfgAccountsOtpVerifyCreate({ ...arg, throwOnError: true });
|
|
3973
4153
|
const data = res.data;
|
|
3974
|
-
void import("./OTPVerifyResponse-
|
|
4154
|
+
void import("./OTPVerifyResponse-P5LDNM7H.mjs").then(({ OTPVerifyResponseSchema }) => {
|
|
3975
4155
|
const parsed = OTPVerifyResponseSchema.safeParse(data);
|
|
3976
4156
|
if (parsed.success) return;
|
|
3977
4157
|
console.warn(
|
|
@@ -4182,7 +4362,7 @@ function useCfgAccountsTokenCreate(config) {
|
|
|
4182
4362
|
async (_key, { arg }) => {
|
|
4183
4363
|
const res = await CfgAccountsAuth.cfgAccountsTokenCreate({ ...arg, throwOnError: true });
|
|
4184
4364
|
const data = res.data;
|
|
4185
|
-
void import("./PasswordLoginResponse-
|
|
4365
|
+
void import("./PasswordLoginResponse-33B576NG.mjs").then(({ PasswordLoginResponseSchema }) => {
|
|
4186
4366
|
const parsed = PasswordLoginResponseSchema.safeParse(data);
|
|
4187
4367
|
if (parsed.success) return;
|
|
4188
4368
|
console.warn(
|
|
@@ -4400,7 +4580,7 @@ var resolveAuthRoutes = /* @__PURE__ */ __name((routes) => ({
|
|
|
4400
4580
|
defaultCallback: routes?.defaultCallback || defaultRoutes.defaultCallback,
|
|
4401
4581
|
defaultAuthCallback: routes?.defaultAuthCallback || routes?.auth || defaultRoutes.defaultAuthCallback
|
|
4402
4582
|
}), "resolveAuthRoutes");
|
|
4403
|
-
var EMAIL_STORAGE_KEY =
|
|
4583
|
+
var EMAIL_STORAGE_KEY = CFG_KEYS.email.key;
|
|
4404
4584
|
var AuthContext = createContext2(void 0);
|
|
4405
4585
|
var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
4406
4586
|
const accounts = useAccountsContext();
|
|
@@ -4547,14 +4727,13 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4547
4727
|
[]
|
|
4548
4728
|
);
|
|
4549
4729
|
const verifyOTP = useCallback11(
|
|
4550
|
-
async (identifier, otpCode, sourceUrl, redirectUrl, skipRedirect
|
|
4730
|
+
async (identifier, otpCode, sourceUrl, redirectUrl, skipRedirect) => {
|
|
4551
4731
|
try {
|
|
4552
4732
|
pendingManualNavRef.current = Boolean(skipRedirect);
|
|
4553
4733
|
const result = await accountsRef.current.verifyOTP({
|
|
4554
4734
|
identifier,
|
|
4555
4735
|
otp: otpCode,
|
|
4556
|
-
source_url: sourceUrl
|
|
4557
|
-
remember_me: rememberMe
|
|
4736
|
+
source_url: sourceUrl
|
|
4558
4737
|
});
|
|
4559
4738
|
if (result.requires_2fa && result.session_id) {
|
|
4560
4739
|
authLogger.info("2FA required, session:", result.session_id);
|
|
@@ -4609,13 +4788,12 @@ var AuthProviderInternal = /* @__PURE__ */ __name(({ children, config }) => {
|
|
|
4609
4788
|
);
|
|
4610
4789
|
const login = useCallback11(
|
|
4611
4790
|
async (email, password, options) => {
|
|
4612
|
-
const { redirectUrl, skipRedirect
|
|
4791
|
+
const { redirectUrl, skipRedirect } = options || {};
|
|
4613
4792
|
try {
|
|
4614
4793
|
pendingManualNavRef.current = Boolean(skipRedirect);
|
|
4615
4794
|
const result = await accountsRef.current.loginWithPassword({
|
|
4616
4795
|
email,
|
|
4617
|
-
password
|
|
4618
|
-
remember_me: rememberMe
|
|
4796
|
+
password
|
|
4619
4797
|
});
|
|
4620
4798
|
if (result.requires_2fa && result.session_id) {
|
|
4621
4799
|
authLogger.info("2FA required, session:", result.session_id);
|