@djangocfg/api 2.1.429 → 2.1.430
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 +58 -40
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.mjs +71 -53
- package/dist/auth.mjs.map +1 -1
- package/package.json +2 -2
- package/src/auth/hooks/useAuthForm.ts +39 -26
- package/src/auth/hooks/useAutoAuth.ts +35 -26
- package/src/auth/hooks/useQueryParams.ts +20 -6
package/dist/auth.cjs
CHANGED
|
@@ -187,10 +187,22 @@ function useQueryParams() {
|
|
|
187
187
|
}, "updateQueryParams");
|
|
188
188
|
updateQueryParams();
|
|
189
189
|
window.addEventListener("popstate", updateQueryParams);
|
|
190
|
-
const
|
|
190
|
+
const origPush = window.history.pushState;
|
|
191
|
+
const origReplace = window.history.replaceState;
|
|
192
|
+
window.history.pushState = function(...args) {
|
|
193
|
+
const result = origPush.apply(this, args);
|
|
194
|
+
updateQueryParams();
|
|
195
|
+
return result;
|
|
196
|
+
};
|
|
197
|
+
window.history.replaceState = function(...args) {
|
|
198
|
+
const result = origReplace.apply(this, args);
|
|
199
|
+
updateQueryParams();
|
|
200
|
+
return result;
|
|
201
|
+
};
|
|
191
202
|
return () => {
|
|
192
203
|
window.removeEventListener("popstate", updateQueryParams);
|
|
193
|
-
|
|
204
|
+
window.history.pushState = origPush;
|
|
205
|
+
window.history.replaceState = origReplace;
|
|
194
206
|
};
|
|
195
207
|
}, [pathname]);
|
|
196
208
|
return queryParams;
|
|
@@ -348,25 +360,27 @@ var useAutoAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
|
348
360
|
const isAllowedPath = allowedPaths.some(
|
|
349
361
|
(path) => normalizedPath === path || normalizedPath.startsWith(path + "/")
|
|
350
362
|
);
|
|
351
|
-
const
|
|
363
|
+
const queryOtp = queryParams.get("otp") || "";
|
|
364
|
+
const queryEmail = queryParams.get("email") || void 0;
|
|
365
|
+
const hasOTP = !!queryOtp;
|
|
352
366
|
const isReady = !!pathname && hasOTP && isAllowedPath;
|
|
367
|
+
const otpValid = queryOtp.length === AUTH_CONSTANTS.EMAIL_OTP_LENGTH;
|
|
368
|
+
const onOTPDetectedRef = (0, import_react5.useRef)(onOTPDetected);
|
|
369
|
+
onOTPDetectedRef.current = onOTPDetected;
|
|
353
370
|
(0, import_react5.useEffect)(() => {
|
|
354
|
-
if (!isReady) return;
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
router.replace(queryString ? `${realPathname}?${queryString}` : realPathname);
|
|
368
|
-
}
|
|
369
|
-
}, [pathname, queryParams, onOTPDetected, cleanupUrl, router, isReady]);
|
|
371
|
+
if (!isReady || !otpValid) return;
|
|
372
|
+
authLogger.info("OTP detected in URL on auth page:", queryOtp);
|
|
373
|
+
onOTPDetectedRef.current?.(queryOtp, queryEmail);
|
|
374
|
+
}, [isReady, otpValid, queryOtp, queryEmail]);
|
|
375
|
+
(0, import_react5.useEffect)(() => {
|
|
376
|
+
if (!isReady || !cleanupUrl || !queryOtp) return;
|
|
377
|
+
const cleanQuery = Object.fromEntries(queryParams.entries());
|
|
378
|
+
delete cleanQuery.otp;
|
|
379
|
+
delete cleanQuery.email;
|
|
380
|
+
const queryString = new URLSearchParams(cleanQuery).toString();
|
|
381
|
+
const realPathname = typeof window !== "undefined" ? window.location.pathname : pathname;
|
|
382
|
+
router.replace(queryString ? `${realPathname}?${queryString}` : realPathname);
|
|
383
|
+
}, [isReady, cleanupUrl, queryOtp]);
|
|
370
384
|
return {
|
|
371
385
|
isReady,
|
|
372
386
|
hasOTP,
|
|
@@ -2761,6 +2775,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
2761
2775
|
const formState = useAuthFormState();
|
|
2762
2776
|
const validation = useAuthValidation();
|
|
2763
2777
|
const isAutoSubmitFromUrlRef = (0, import_react7.useRef)(false);
|
|
2778
|
+
const processedOtpKeyRef = (0, import_react7.useRef)(null);
|
|
2764
2779
|
const {
|
|
2765
2780
|
requestOTP,
|
|
2766
2781
|
verifyOTP,
|
|
@@ -2971,29 +2986,32 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
2971
2986
|
setTwoFactorCode("");
|
|
2972
2987
|
clearError();
|
|
2973
2988
|
}, [setUseBackupCode, setTwoFactorCode, clearError]);
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2989
|
+
const handleOTPFromUrl = (0, import_react7.useCallback)((detectedOtp, detectedEmail) => {
|
|
2990
|
+
const autoIdentifier = detectedEmail || getSavedEmail() || "";
|
|
2991
|
+
if (!autoIdentifier) {
|
|
2992
|
+
authLogger.warn("No identifier found for auto-submit (no email in URL or storage)");
|
|
2993
|
+
return;
|
|
2994
|
+
}
|
|
2995
|
+
const otpKey = `${autoIdentifier}:${detectedOtp}`;
|
|
2996
|
+
if (processedOtpKeyRef.current === otpKey) return;
|
|
2997
|
+
if (isAutoSubmitFromUrlRef.current) return;
|
|
2998
|
+
processedOtpKeyRef.current = otpKey;
|
|
2999
|
+
isAutoSubmitFromUrlRef.current = true;
|
|
3000
|
+
authLogger.info("OTP detected from URL, auto-submitting");
|
|
3001
|
+
setIdentifier(autoIdentifier);
|
|
3002
|
+
setOtp(detectedOtp);
|
|
3003
|
+
setStep("otp");
|
|
3004
|
+
setTimeout(async () => {
|
|
3005
|
+
try {
|
|
3006
|
+
await submitOTP(autoIdentifier, detectedOtp);
|
|
3007
|
+
} finally {
|
|
2983
3008
|
isAutoSubmitFromUrlRef.current = false;
|
|
2984
|
-
return;
|
|
2985
3009
|
}
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
await submitOTP(autoIdentifier, detectedOtp);
|
|
2992
|
-
} finally {
|
|
2993
|
-
isAutoSubmitFromUrlRef.current = false;
|
|
2994
|
-
}
|
|
2995
|
-
}, 100);
|
|
2996
|
-
}, "onOTPDetected"),
|
|
3010
|
+
}, 100);
|
|
3011
|
+
}, [getSavedEmail, setIdentifier, setOtp, setStep, submitOTP]);
|
|
3012
|
+
useAutoAuth({
|
|
3013
|
+
allowedPaths: [authPath],
|
|
3014
|
+
onOTPDetected: handleOTPFromUrl,
|
|
2997
3015
|
cleanupUrl: true
|
|
2998
3016
|
});
|
|
2999
3017
|
return {
|