@djangocfg/api 2.1.47 → 2.1.49

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 CHANGED
@@ -4700,34 +4700,37 @@ var import_navigation2 = require("next/navigation");
4700
4700
  var import_react6 = require("react");
4701
4701
  var import_hooks4 = require("@djangocfg/ui-nextjs/hooks");
4702
4702
  var useAutoAuth = /* @__PURE__ */ __name((options = {}) => {
4703
- const { onOTPDetected, cleanupUrl = true } = options;
4703
+ const { onOTPDetected, cleanupUrl = true, allowedPaths = ["/auth"] } = options;
4704
4704
  const queryParams = (0, import_hooks4.useQueryParams)();
4705
4705
  const pathname = (0, import_navigation2.usePathname)();
4706
4706
  const router = (0, import_hooks4.useCfgRouter)();
4707
- const isReady = !!pathname && !!queryParams.get("otp");
4707
+ const isAllowedPath = allowedPaths.some((path) => pathname === path || pathname?.startsWith(path + "/"));
4708
4708
  const hasOTP = !!queryParams.get("otp");
4709
+ const isReady = !!pathname && hasOTP && isAllowedPath;
4709
4710
  (0, import_react6.useEffect)(() => {
4710
4711
  if (!isReady) return;
4711
4712
  const queryOtp = queryParams.get("otp");
4712
4713
  if (queryOtp && typeof queryOtp === "string" && queryOtp.length === 6) {
4713
- authLogger.info("OTP detected in URL:", queryOtp);
4714
+ authLogger.info("OTP detected in URL on auth page:", queryOtp);
4714
4715
  onOTPDetected?.(queryOtp);
4715
4716
  }
4716
4717
  if (cleanupUrl && queryOtp) {
4717
4718
  const cleanQuery = Object.fromEntries(queryParams.entries());
4718
4719
  delete cleanQuery.otp;
4719
- router.push(`${pathname}?${new URLSearchParams(cleanQuery).toString()}`);
4720
+ const queryString = new URLSearchParams(cleanQuery).toString();
4721
+ router.push(queryString ? `${pathname}?${queryString}` : pathname);
4720
4722
  }
4721
- }, [pathname, queryParams, onOTPDetected, cleanupUrl, router]);
4723
+ }, [pathname, queryParams, onOTPDetected, cleanupUrl, router, isReady]);
4722
4724
  return {
4723
4725
  isReady,
4724
- hasOTP
4726
+ hasOTP,
4727
+ isAllowedPath
4725
4728
  };
4726
4729
  }, "useAutoAuth");
4727
4730
 
4728
4731
  // src/auth/hooks/useAuthForm.ts
4729
4732
  var useAuthForm = /* @__PURE__ */ __name((options) => {
4730
- const { onIdentifierSuccess, onOTPSuccess, onError, sourceUrl, redirectUrl, requireTermsAcceptance = false } = options;
4733
+ const { onIdentifierSuccess, onOTPSuccess, onError, sourceUrl, redirectUrl, requireTermsAcceptance = false, authPath = "/auth" } = options;
4731
4734
  const [identifier, setIdentifier] = (0, import_react7.useState)("");
4732
4735
  const [channel, setChannel] = (0, import_react7.useState)("email");
4733
4736
  const [otp, setOtp] = (0, import_react7.useState)("");
@@ -4901,6 +4904,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
4901
4904
  setSavedTermsAccepted(checked);
4902
4905
  }, [setSavedTermsAccepted]);
4903
4906
  useAutoAuth({
4907
+ allowedPaths: [authPath],
4904
4908
  onOTPDetected: /* @__PURE__ */ __name((otp2) => {
4905
4909
  authLogger.info("OTP detected, auto-submitting");
4906
4910
  const savedEmail2 = getSavedEmail();