@djangocfg/api 2.1.420 → 2.1.422
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-server.cjs +45 -27
- package/dist/auth-server.cjs.map +1 -1
- package/dist/auth-server.mjs +45 -27
- package/dist/auth-server.mjs.map +1 -1
- package/dist/auth.cjs +61 -33
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +2 -1
- package/dist/auth.d.ts +2 -1
- package/dist/auth.mjs +61 -33
- package/dist/auth.mjs.map +1 -1
- package/dist/clients.cjs +45 -27
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.d.cts +1 -1
- package/dist/clients.d.ts +1 -1
- package/dist/clients.mjs +45 -27
- package/dist/clients.mjs.map +1 -1
- package/dist/hooks.cjs +48 -29
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.mjs +48 -29
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.cjs +45 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +45 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsApiKeyRetrieve.ts +12 -3
- package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthConnectionsList.ts +12 -3
- package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthProvidersRetrieve.ts +12 -3
- package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsProfileRetrieve.ts +12 -3
- package/src/_api/generated/_cfg_accounts/openapi.json +9 -0
- package/src/_api/generated/_cfg_centrifugo/hooks/useCfgCentrifugoAuthTokenRetrieve.ts +12 -3
- package/src/_api/generated/_cfg_totp/hooks/useCfgTotpBackupCodesRetrieve.ts +12 -3
- package/src/_api/generated/_cfg_totp/hooks/useCfgTotpDevicesRetrieve.ts +12 -3
- package/src/_api/generated/client/client.gen.ts +1 -4
- package/src/_api/generated/client/types.gen.ts +3 -2
- package/src/_api/generated/client/utils.gen.ts +6 -8
- package/src/_api/generated/core/params.gen.ts +4 -4
- package/src/_api/generated/helpers/auth.ts +58 -9
- package/src/_api/generated/index.ts +6 -0
- package/src/_api/generated/openapi.json +9 -0
- package/src/_api/generated/sdk.gen.ts +18 -6
- package/src/auth/hooks/useAuthForm.ts +5 -4
- package/src/auth/hooks/useAutoAuth.ts +23 -4
package/dist/auth.cjs
CHANGED
|
@@ -291,24 +291,35 @@ var authLogger = logger.withTag("auth");
|
|
|
291
291
|
// src/auth/hooks/useAutoAuth.ts
|
|
292
292
|
var import_navigation3 = require("next/navigation");
|
|
293
293
|
var import_react5 = require("react");
|
|
294
|
+
var normalizePath = /* @__PURE__ */ __name((path) => {
|
|
295
|
+
if (!path) return "";
|
|
296
|
+
const withoutLocale = path.replace(/^\/[a-z]{2}(?=\/|$)/, "");
|
|
297
|
+
const trimmed = withoutLocale.replace(/\/+$/, "");
|
|
298
|
+
return trimmed || "/";
|
|
299
|
+
}, "normalizePath");
|
|
294
300
|
var useAutoAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
295
301
|
const { onOTPDetected, cleanupUrl = true, allowedPaths = ["/auth"] } = options;
|
|
296
302
|
const queryParams = useQueryParams();
|
|
297
303
|
const pathname = (0, import_navigation3.usePathname)();
|
|
298
304
|
const router = useCfgRouter();
|
|
299
|
-
const
|
|
305
|
+
const normalizedPath = normalizePath(pathname);
|
|
306
|
+
const isAllowedPath = allowedPaths.some(
|
|
307
|
+
(path) => normalizedPath === path || normalizedPath.startsWith(path + "/")
|
|
308
|
+
);
|
|
300
309
|
const hasOTP = !!queryParams.get("otp");
|
|
301
310
|
const isReady = !!pathname && hasOTP && isAllowedPath;
|
|
302
311
|
(0, import_react5.useEffect)(() => {
|
|
303
312
|
if (!isReady) return;
|
|
304
313
|
const queryOtp = queryParams.get("otp");
|
|
314
|
+
const queryEmail = queryParams.get("email") || void 0;
|
|
305
315
|
if (queryOtp && typeof queryOtp === "string" && queryOtp.length === AUTH_CONSTANTS.EMAIL_OTP_LENGTH) {
|
|
306
316
|
authLogger.info("OTP detected in URL on auth page:", queryOtp);
|
|
307
|
-
onOTPDetected?.(queryOtp);
|
|
317
|
+
onOTPDetected?.(queryOtp, queryEmail);
|
|
308
318
|
}
|
|
309
319
|
if (cleanupUrl && queryOtp) {
|
|
310
320
|
const cleanQuery = Object.fromEntries(queryParams.entries());
|
|
311
321
|
delete cleanQuery.otp;
|
|
322
|
+
delete cleanQuery.email;
|
|
312
323
|
const queryString = new URLSearchParams(cleanQuery).toString();
|
|
313
324
|
const realPathname = typeof window !== "undefined" ? window.location.pathname : pathname;
|
|
314
325
|
router.replace(queryString ? `${realPathname}?${queryString}` : realPathname);
|
|
@@ -451,6 +462,18 @@ function detectLocale() {
|
|
|
451
462
|
}
|
|
452
463
|
__name(detectLocale, "detectLocale");
|
|
453
464
|
function defaultBaseUrl() {
|
|
465
|
+
if (typeof window !== "undefined") {
|
|
466
|
+
try {
|
|
467
|
+
if (typeof process !== "undefined" && process.env) {
|
|
468
|
+
if (process.env.NEXT_PUBLIC_STATIC_BUILD === "true") return "";
|
|
469
|
+
if (process.env.NEXT_PUBLIC_API_PROXY_URL !== void 0)
|
|
470
|
+
return process.env.NEXT_PUBLIC_API_PROXY_URL;
|
|
471
|
+
return process.env.NEXT_PUBLIC_API_URL || "";
|
|
472
|
+
}
|
|
473
|
+
} catch {
|
|
474
|
+
}
|
|
475
|
+
return "";
|
|
476
|
+
}
|
|
454
477
|
try {
|
|
455
478
|
if (typeof process !== "undefined" && process.env) {
|
|
456
479
|
if (process.env.NEXT_PUBLIC_STATIC_BUILD === "true") return "";
|
|
@@ -462,7 +485,6 @@ function defaultBaseUrl() {
|
|
|
462
485
|
}
|
|
463
486
|
__name(defaultBaseUrl, "defaultBaseUrl");
|
|
464
487
|
function defaultApiKey() {
|
|
465
|
-
if (isBrowser2) return null;
|
|
466
488
|
try {
|
|
467
489
|
if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_API_KEY) {
|
|
468
490
|
return process.env.NEXT_PUBLIC_API_KEY;
|
|
@@ -618,7 +640,7 @@ function installAuthOnClient(client2) {
|
|
|
618
640
|
const locale = auth.getLocale();
|
|
619
641
|
if (locale) request.headers.set("Accept-Language", locale);
|
|
620
642
|
const apiKey = auth.getApiKey();
|
|
621
|
-
if (apiKey) request.headers.set("X-API-Key", apiKey);
|
|
643
|
+
if (apiKey && !request.headers.has("X-API-Key")) request.headers.set("X-API-Key", apiKey);
|
|
622
644
|
try {
|
|
623
645
|
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
624
646
|
if (tz) request.headers.set("X-Timezone", tz);
|
|
@@ -1257,11 +1279,8 @@ var checkForExistence = /* @__PURE__ */ __name((options, name) => {
|
|
|
1257
1279
|
}
|
|
1258
1280
|
return false;
|
|
1259
1281
|
}, "checkForExistence");
|
|
1260
|
-
|
|
1261
|
-
security
|
|
1262
|
-
...options
|
|
1263
|
-
}) => {
|
|
1264
|
-
for (const auth2 of security) {
|
|
1282
|
+
async function setAuthParams(options) {
|
|
1283
|
+
for (const auth2 of options.security ?? []) {
|
|
1265
1284
|
if (checkForExistence(options, auth2.name)) {
|
|
1266
1285
|
continue;
|
|
1267
1286
|
}
|
|
@@ -1286,7 +1305,8 @@ var setAuthParams = /* @__PURE__ */ __name(async ({
|
|
|
1286
1305
|
break;
|
|
1287
1306
|
}
|
|
1288
1307
|
}
|
|
1289
|
-
}
|
|
1308
|
+
}
|
|
1309
|
+
__name(setAuthParams, "setAuthParams");
|
|
1290
1310
|
var buildUrl = /* @__PURE__ */ __name((options) => getUrl({
|
|
1291
1311
|
baseUrl: options.baseUrl,
|
|
1292
1312
|
path: options.path,
|
|
@@ -1415,10 +1435,7 @@ var createClient = /* @__PURE__ */ __name((config = {}) => {
|
|
|
1415
1435
|
serializedBody: void 0
|
|
1416
1436
|
};
|
|
1417
1437
|
if (opts.security) {
|
|
1418
|
-
await setAuthParams(
|
|
1419
|
-
...opts,
|
|
1420
|
-
security: opts.security
|
|
1421
|
-
});
|
|
1438
|
+
await setAuthParams(opts);
|
|
1422
1439
|
}
|
|
1423
1440
|
if (opts.requestValidator) {
|
|
1424
1441
|
await opts.requestValidator(opts);
|
|
@@ -1611,11 +1628,15 @@ var CfgAccountsApiKey = class {
|
|
|
1611
1628
|
*/
|
|
1612
1629
|
static cfgAccountsApiKeyRetrieve(options) {
|
|
1613
1630
|
return (options?.client ?? client).get({
|
|
1614
|
-
security: [
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1631
|
+
security: [
|
|
1632
|
+
{ scheme: "bearer", type: "http" },
|
|
1633
|
+
{
|
|
1634
|
+
in: "cookie",
|
|
1635
|
+
name: "sessionid",
|
|
1636
|
+
type: "apiKey"
|
|
1637
|
+
},
|
|
1638
|
+
{ name: "X-API-Key", type: "apiKey" }
|
|
1639
|
+
],
|
|
1619
1640
|
url: "/cfg/accounts/api-key/",
|
|
1620
1641
|
...options
|
|
1621
1642
|
});
|
|
@@ -1627,11 +1648,15 @@ var CfgAccountsApiKey = class {
|
|
|
1627
1648
|
*/
|
|
1628
1649
|
static cfgAccountsApiKeyRegenerateCreate(options) {
|
|
1629
1650
|
return (options.client ?? client).post({
|
|
1630
|
-
security: [
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1651
|
+
security: [
|
|
1652
|
+
{ scheme: "bearer", type: "http" },
|
|
1653
|
+
{
|
|
1654
|
+
in: "cookie",
|
|
1655
|
+
name: "sessionid",
|
|
1656
|
+
type: "apiKey"
|
|
1657
|
+
},
|
|
1658
|
+
{ name: "X-API-Key", type: "apiKey" }
|
|
1659
|
+
],
|
|
1635
1660
|
url: "/cfg/accounts/api-key/regenerate/",
|
|
1636
1661
|
...options,
|
|
1637
1662
|
headers: {
|
|
@@ -1647,11 +1672,15 @@ var CfgAccountsApiKey = class {
|
|
|
1647
1672
|
*/
|
|
1648
1673
|
static cfgAccountsApiKeyTestCreate(options) {
|
|
1649
1674
|
return (options.client ?? client).post({
|
|
1650
|
-
security: [
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1675
|
+
security: [
|
|
1676
|
+
{ scheme: "bearer", type: "http" },
|
|
1677
|
+
{
|
|
1678
|
+
in: "cookie",
|
|
1679
|
+
name: "sessionid",
|
|
1680
|
+
type: "apiKey"
|
|
1681
|
+
},
|
|
1682
|
+
{ name: "X-API-Key", type: "apiKey" }
|
|
1683
|
+
],
|
|
1655
1684
|
url: "/cfg/accounts/api-key/test/",
|
|
1656
1685
|
...options,
|
|
1657
1686
|
headers: {
|
|
@@ -2717,14 +2746,13 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
2717
2746
|
}, [setUseBackupCode, setTwoFactorCode, clearError]);
|
|
2718
2747
|
useAutoAuth({
|
|
2719
2748
|
allowedPaths: [authPath],
|
|
2720
|
-
onOTPDetected: /* @__PURE__ */ __name((detectedOtp) => {
|
|
2749
|
+
onOTPDetected: /* @__PURE__ */ __name((detectedOtp, detectedEmail) => {
|
|
2721
2750
|
if (isAutoSubmitFromUrlRef.current || isLoading) return;
|
|
2722
2751
|
isAutoSubmitFromUrlRef.current = true;
|
|
2723
2752
|
authLogger.info("OTP detected from URL, auto-submitting");
|
|
2724
|
-
const
|
|
2725
|
-
const autoIdentifier = savedEmail || "";
|
|
2753
|
+
const autoIdentifier = detectedEmail || getSavedEmail() || "";
|
|
2726
2754
|
if (!autoIdentifier) {
|
|
2727
|
-
authLogger.warn("No
|
|
2755
|
+
authLogger.warn("No identifier found for auto-submit (no email in URL or storage)");
|
|
2728
2756
|
isAutoSubmitFromUrlRef.current = false;
|
|
2729
2757
|
return;
|
|
2730
2758
|
}
|