From 8520b77893686d0685af4cbcdf5da075206164d0 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Thu, 19 Sep 2024 08:15:23 -0400 Subject: [PATCH] allow logging into accounts that have tfa enabled --- src/components/auth/auth-form.tsx | 61 +++++++++++++++---- .../user/settings/tfa/tfa-setup-form.tsx | 2 - 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/components/auth/auth-form.tsx b/src/components/auth/auth-form.tsx index 66bb445..0eb008b 100644 --- a/src/components/auth/auth-form.tsx +++ b/src/components/auth/auth-form.tsx @@ -24,6 +24,13 @@ import { UserAuthResponse } from "@/app/types/user/response/user-auth-response"; import { hasFlag } from "@/lib/user"; import { UserFlag } from "@/app/types/user/user-flag"; import { User } from "@/app/types/user/user"; +import { + InputOTP, + InputOTPGroup, + InputOTPSeparator, + InputOTPSlot, +} from "@/components/ui/input-otp"; +import { cn } from "@/lib/utils"; /** * Define the form schemas for the various stages. @@ -60,6 +67,7 @@ const RegisterSchema = z const LoginSchema = z.object({ email: buildEmailInput(true), password: z.string(), + pin: z.string().optional(), }); /** @@ -81,6 +89,10 @@ const AuthForm = (): ReactElement => { const [captchaResponse, setCaptchaResponse] = useState( undefined ); + + const [borderCrossing, setBorderCrossing] = useState(false); + const [tfaPin, setTfaPin] = useState(); + const [error, setError] = useState(undefined); const turnstile: TurnstileObject = useTurnstile(); const cookies: Cookies = useCookies(); @@ -133,8 +145,16 @@ const AuthForm = (): ReactElement => { email, password, captchaResponse, + tfaPin: tfaPin ?? "", }, }); + + // Handle two-factor auth + if (error?.message === "BORDER_CROSSING") { + setBorderCrossing(true); + setLoading(false); + return; + } setError(error?.message ?? undefined); // Reset the captcha if auth fails @@ -164,16 +184,18 @@ const AuthForm = (): ReactElement => { return (
{/* Email Address */} -
- - -
+ {!borderCrossing && ( +
+ + +
+ )} {/* Username */} {stage === "register" && ( @@ -195,7 +217,7 @@ const AuthForm = (): ReactElement => { )} {/* Password */} - {stage !== "email" && ( + {stage !== "email" && !borderCrossing && ( { )} + {/* TFA Pin */} +
+ + + {[0, 1, 2].map((index: number) => ( + + ))} + + + + {[3, 4, 5].map((index: number) => ( + + ))} + + +
+ {/* Password Confirmation */} {stage === "register" && (