"use client"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { client } from "@/lib/auth-client"; import { AlertCircle, CheckCircle2, Mail } from "lucide-react"; import { useRouter } from "next/navigation"; import { useState } from "react"; export default function Component() { const [otp, setOtp] = useState(""); const [isOtpSent, setIsOtpSent] = useState(false); const [message, setMessage] = useState(""); const [isError, setIsError] = useState(false); const [isValidated, setIsValidated] = useState(false); // In a real app, this email would come from your authentication context const userEmail = "user@example.com"; const requestOTP = async () => { const res = await client.twoFactor.sendOtp(); // In a real app, this would call your backend API to send the OTP setMessage("OTP sent to your email"); setIsError(false); setIsOtpSent(true); }; const router = useRouter(); const validateOTP = async () => { const res = await client.twoFactor.verifyOtp({ code: otp, }); if (res.data) { setMessage("OTP validated successfully"); setIsError(false); setIsValidated(true); router.push("/"); } else { setIsError(true); setMessage("Invalid OTP"); } }; return (
Two-Factor Authentication Verify your identity with a one-time password
{!isOtpSent ? ( ) : ( <>
setOtp(e.target.value)} maxLength={6} />
)}
{message && (
{isError ? ( ) : ( )}

{message}

)}
); }