import { Button, Center, Col, Grid, Image, Stack, Text, TextInput, Title, Tooltip, } from "@mantine/core"; import { useForm, yupResolver } from "@mantine/form"; import { useModals } from "@mantine/modals"; import { ModalsContextProps } from "@mantine/modals/lib/context"; import * as yup from "yup"; import useUser from "../../hooks/user.hook"; import authService from "../../services/auth.service"; import toast from "../../utils/toast.util"; const showEnableTotpModal = ( modals: ModalsContextProps, refreshUser: () => {}, options: { qrCode: string; secret: string; password: string; } ) => { return modals.openModal({ title: Enable TOTP, children: ( ), }); }; const CreateEnableTotpModal = ({ options, refreshUser, }: { options: { qrCode: string; secret: string; password: string; }; refreshUser: () => {}; }) => { const modals = useModals(); const user = useUser(); console.log(user.user); const validationSchema = yup.object().shape({ code: yup .string() .min(6) .max(6) .required() .matches(/^[0-9]+$/, { message: "Code must be a number" }), }); const form = useForm({ initialValues: { code: "", }, validate: yupResolver(validationSchema), }); return (
Step 1: Add your authenticator QR Code
OR
Enter manually
Step 2: Validate your code
{ authService .verifyTOTP(values.code, options.password) .then(() => { toast.success("Successfully enabled TOTP"); modals.closeAll(); refreshUser(); }) .catch(toast.axiosError); })} >
); }; export default showEnableTotpModal;