Skip to content

Commit 44b8d78

Browse files
amanaman
authored andcommitted
Fix stale OTP value on auto-submit
1 parent c1c2edf commit 44b8d78

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

apps/web/ui/auth/register/verify-email-form.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,19 @@ export const VerifyEmailForm = () => {
5151
return;
5252
}
5353

54+
const handleVerify = (completedCode?: string) => {
55+
if (isPending || isRedirecting) return;
56+
const finalCode = (completedCode ?? code).trim();
57+
if (!finalCode || finalCode.length < 6) return;
58+
executeAsync({ email, password, code: finalCode });
59+
};
60+
5461
return (
5562
<div className="flex flex-col gap-3">
5663
<form
5764
onSubmit={(e) => {
5865
e.preventDefault();
59-
executeAsync({ email, password, code });
66+
handleVerify();
6067
}}
6168
>
6269
<div>
@@ -65,7 +72,7 @@ export const VerifyEmailForm = () => {
6572
value={code}
6673
onChange={(code) => {
6774
setIsInvalidCode(false);
68-
setCode(code);
75+
setCode(code.trim());
6976
}}
7077
autoFocus={!isMobile}
7178
render={({ slots }) => (
@@ -85,14 +92,14 @@ export const VerifyEmailForm = () => {
8592
{hasFakeCaret && (
8693
<div className="animate-caret-blink pointer-events-none absolute inset-0 flex items-center justify-center">
8794
<div className="h-5 w-px bg-black" />
88-
</div>
95+
</div>
8996
)}
9097
</div>
9198
))}
9299
</div>
93100
)}
94-
onComplete={() => {
95-
executeAsync({ email, password, code });
101+
onComplete={(completedCode) => {
102+
handleVerify(completedCode);
96103
}}
97104
/>
98105
<AnimatedSizeContainer height>
@@ -108,12 +115,12 @@ export const VerifyEmailForm = () => {
108115
text={isPending ? "Verifying..." : "Continue"}
109116
type="submit"
110117
loading={isPending || isRedirecting}
111-
disabled={!code || code.length < 6}
118+
disabled={isPending || isRedirecting || code.length < 6}
112119
/>
113120
</div>
114121
</form>
115122

116123
<ResendOtp email={email} />
117124
</div>
118125
);
119-
};
126+
};

0 commit comments

Comments
 (0)