mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 12:45:47 +00:00
* wip * feat: finalize totp gen code * refactor: split login screen and forms * feat: add totp logic and ui * refactor: make totp pending expiry time fixed * refactor: skip all checks when disable continue is enabled * fix: fix cli not exiting on invalid input
41 lines
854 B
TypeScript
41 lines
854 B
TypeScript
import { Button, PinInput } from "@mantine/core";
|
|
import { useForm, zodResolver } from "@mantine/form";
|
|
import { z } from "zod";
|
|
|
|
const schema = z.object({
|
|
code: z.string(),
|
|
});
|
|
|
|
type FormValues = z.infer<typeof schema>;
|
|
|
|
interface TotpFormProps {
|
|
onSubmit: (values: FormValues) => void;
|
|
isLoading: boolean;
|
|
}
|
|
|
|
export const TotpForm = (props: TotpFormProps) => {
|
|
const { onSubmit, isLoading } = props;
|
|
|
|
const form = useForm({
|
|
mode: "uncontrolled",
|
|
initialValues: {
|
|
code: "",
|
|
},
|
|
validate: zodResolver(schema),
|
|
});
|
|
|
|
return (
|
|
<form onSubmit={form.onSubmit(onSubmit)}>
|
|
<PinInput
|
|
length={6}
|
|
type={"number"}
|
|
placeholder=""
|
|
{...form.getInputProps("code")}
|
|
/>
|
|
<Button type="submit" mt="xl" loading={isLoading} fullWidth>
|
|
Verify
|
|
</Button>
|
|
</form>
|
|
);
|
|
};
|