@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 +11 -7
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +5 -0
- package/dist/auth.d.ts +5 -0
- package/dist/auth.mjs +11 -7
- package/dist/auth.mjs.map +1 -1
- package/package.json +3 -3
- package/src/auth/hooks/useAuthForm.ts +9 -6
- package/src/auth/hooks/useAutoAuth.ts +14 -6
package/dist/auth.d.cts
CHANGED
|
@@ -377,12 +377,16 @@ interface UseAuthFormOptions {
|
|
|
377
377
|
redirectUrl?: string;
|
|
378
378
|
/** If true, user must accept terms before submitting. Default: false */
|
|
379
379
|
requireTermsAcceptance?: boolean;
|
|
380
|
+
/** Path to auth page for auto-OTP detection. Default: '/auth' */
|
|
381
|
+
authPath?: string;
|
|
380
382
|
}
|
|
381
383
|
declare const useAuthForm: (options: UseAuthFormOptions) => AuthFormState & AuthFormHandlers;
|
|
382
384
|
|
|
383
385
|
interface UseAutoAuthOptions {
|
|
384
386
|
onOTPDetected?: (otp: string) => void;
|
|
385
387
|
cleanupUrl?: boolean;
|
|
388
|
+
/** Paths where auto-auth should be active. Default: ['/auth'] */
|
|
389
|
+
allowedPaths?: string[];
|
|
386
390
|
}
|
|
387
391
|
/**
|
|
388
392
|
* Hook for automatic authentication from URL query parameters
|
|
@@ -391,6 +395,7 @@ interface UseAutoAuthOptions {
|
|
|
391
395
|
declare const useAutoAuth: (options?: UseAutoAuthOptions) => {
|
|
392
396
|
isReady: boolean;
|
|
393
397
|
hasOTP: boolean;
|
|
398
|
+
isAllowedPath: boolean;
|
|
394
399
|
};
|
|
395
400
|
|
|
396
401
|
interface UseGithubAuthOptions {
|
package/dist/auth.d.ts
CHANGED
|
@@ -377,12 +377,16 @@ interface UseAuthFormOptions {
|
|
|
377
377
|
redirectUrl?: string;
|
|
378
378
|
/** If true, user must accept terms before submitting. Default: false */
|
|
379
379
|
requireTermsAcceptance?: boolean;
|
|
380
|
+
/** Path to auth page for auto-OTP detection. Default: '/auth' */
|
|
381
|
+
authPath?: string;
|
|
380
382
|
}
|
|
381
383
|
declare const useAuthForm: (options: UseAuthFormOptions) => AuthFormState & AuthFormHandlers;
|
|
382
384
|
|
|
383
385
|
interface UseAutoAuthOptions {
|
|
384
386
|
onOTPDetected?: (otp: string) => void;
|
|
385
387
|
cleanupUrl?: boolean;
|
|
388
|
+
/** Paths where auto-auth should be active. Default: ['/auth'] */
|
|
389
|
+
allowedPaths?: string[];
|
|
386
390
|
}
|
|
387
391
|
/**
|
|
388
392
|
* Hook for automatic authentication from URL query parameters
|
|
@@ -391,6 +395,7 @@ interface UseAutoAuthOptions {
|
|
|
391
395
|
declare const useAutoAuth: (options?: UseAutoAuthOptions) => {
|
|
392
396
|
isReady: boolean;
|
|
393
397
|
hasOTP: boolean;
|
|
398
|
+
isAllowedPath: boolean;
|
|
394
399
|
};
|
|
395
400
|
|
|
396
401
|
interface UseGithubAuthOptions {
|
package/dist/auth.mjs
CHANGED
|
@@ -4660,34 +4660,37 @@ import { usePathname as usePathname2 } from "next/navigation";
|
|
|
4660
4660
|
import { useEffect as useEffect5 } from "react";
|
|
4661
4661
|
import { useCfgRouter as useCfgRouter3, useQueryParams as useQueryParams2 } from "@djangocfg/ui-nextjs/hooks";
|
|
4662
4662
|
var useAutoAuth = /* @__PURE__ */ __name((options = {}) => {
|
|
4663
|
-
const { onOTPDetected, cleanupUrl = true } = options;
|
|
4663
|
+
const { onOTPDetected, cleanupUrl = true, allowedPaths = ["/auth"] } = options;
|
|
4664
4664
|
const queryParams = useQueryParams2();
|
|
4665
4665
|
const pathname = usePathname2();
|
|
4666
4666
|
const router = useCfgRouter3();
|
|
4667
|
-
const
|
|
4667
|
+
const isAllowedPath = allowedPaths.some((path) => pathname === path || pathname?.startsWith(path + "/"));
|
|
4668
4668
|
const hasOTP = !!queryParams.get("otp");
|
|
4669
|
+
const isReady = !!pathname && hasOTP && isAllowedPath;
|
|
4669
4670
|
useEffect5(() => {
|
|
4670
4671
|
if (!isReady) return;
|
|
4671
4672
|
const queryOtp = queryParams.get("otp");
|
|
4672
4673
|
if (queryOtp && typeof queryOtp === "string" && queryOtp.length === 6) {
|
|
4673
|
-
authLogger.info("OTP detected in URL:", queryOtp);
|
|
4674
|
+
authLogger.info("OTP detected in URL on auth page:", queryOtp);
|
|
4674
4675
|
onOTPDetected?.(queryOtp);
|
|
4675
4676
|
}
|
|
4676
4677
|
if (cleanupUrl && queryOtp) {
|
|
4677
4678
|
const cleanQuery = Object.fromEntries(queryParams.entries());
|
|
4678
4679
|
delete cleanQuery.otp;
|
|
4679
|
-
|
|
4680
|
+
const queryString = new URLSearchParams(cleanQuery).toString();
|
|
4681
|
+
router.push(queryString ? `${pathname}?${queryString}` : pathname);
|
|
4680
4682
|
}
|
|
4681
|
-
}, [pathname, queryParams, onOTPDetected, cleanupUrl, router]);
|
|
4683
|
+
}, [pathname, queryParams, onOTPDetected, cleanupUrl, router, isReady]);
|
|
4682
4684
|
return {
|
|
4683
4685
|
isReady,
|
|
4684
|
-
hasOTP
|
|
4686
|
+
hasOTP,
|
|
4687
|
+
isAllowedPath
|
|
4685
4688
|
};
|
|
4686
4689
|
}, "useAutoAuth");
|
|
4687
4690
|
|
|
4688
4691
|
// src/auth/hooks/useAuthForm.ts
|
|
4689
4692
|
var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
4690
|
-
const { onIdentifierSuccess, onOTPSuccess, onError, sourceUrl, redirectUrl, requireTermsAcceptance = false } = options;
|
|
4693
|
+
const { onIdentifierSuccess, onOTPSuccess, onError, sourceUrl, redirectUrl, requireTermsAcceptance = false, authPath = "/auth" } = options;
|
|
4691
4694
|
const [identifier, setIdentifier] = useState6("");
|
|
4692
4695
|
const [channel, setChannel] = useState6("email");
|
|
4693
4696
|
const [otp, setOtp] = useState6("");
|
|
@@ -4861,6 +4864,7 @@ var useAuthForm = /* @__PURE__ */ __name((options) => {
|
|
|
4861
4864
|
setSavedTermsAccepted(checked);
|
|
4862
4865
|
}, [setSavedTermsAccepted]);
|
|
4863
4866
|
useAutoAuth({
|
|
4867
|
+
allowedPaths: [authPath],
|
|
4864
4868
|
onOTPDetected: /* @__PURE__ */ __name((otp2) => {
|
|
4865
4869
|
authLogger.info("OTP detected, auto-submitting");
|
|
4866
4870
|
const savedEmail2 = getSavedEmail();
|