Skip to content

Commit 252ba10

Browse files
committed
feat: auto submit totp code when it is filled
1 parent 6431afb commit 252ba10

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

frontend/src/components/auth/totp-form.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ import z from "zod";
1414
interface Props {
1515
formId: string;
1616
onSubmit: (code: TotpSchema) => void;
17-
loading?: boolean;
1817
}
1918

2019
export const TotpForm = (props: Props) => {
21-
const { formId, onSubmit, loading } = props;
20+
const { formId, onSubmit } = props;
2221
const { t } = useTranslation();
2322

2423
z.config({
@@ -30,6 +29,14 @@ export const TotpForm = (props: Props) => {
3029
resolver: zodResolver(totpSchema),
3130
});
3231

32+
const handleChange = (value: string) => {
33+
form.setValue("code", value, { shouldDirty: true, shouldValidate: true });
34+
35+
if (value.length === 6) {
36+
onSubmit({ code: value });
37+
}
38+
};
39+
3340
return (
3441
<Form {...form}>
3542
<form id={formId} onSubmit={form.handleSubmit(onSubmit)}>
@@ -41,10 +48,10 @@ export const TotpForm = (props: Props) => {
4148
<FormControl>
4249
<InputOTP
4350
maxLength={6}
44-
disabled={loading}
4551
{...field}
4652
autoComplete="one-time-code"
4753
autoFocus
54+
onChange={handleChange}
4855
>
4956
<InputOTPGroup>
5057
<InputOTPSlot index={0} />

frontend/src/pages/totp-page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export const TotpPage = () => {
7070
<TotpForm
7171
formId={formId}
7272
onSubmit={(values) => totpMutation.mutate(values)}
73-
loading={totpMutation.isPending}
7473
/>
7574
</CardContent>
7675
<CardFooter className="flex flex-col items-stretch">

0 commit comments

Comments
 (0)