diff --git a/frontend/app/_components/Otp.tsx b/frontend/app/_components/Otp.tsx index 57428cca..b82783d3 100644 --- a/frontend/app/_components/Otp.tsx +++ b/frontend/app/_components/Otp.tsx @@ -3,13 +3,14 @@ import { Button } from "@/components/ui/button"; import Link from "next/link"; import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot } from "@/components/ui/input-otp"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import { BACKEND_URL } from "@/lib/utils"; import { toast } from "sonner"; import { Mail } from "lucide-react"; export function Otp({ email }: { email: string }) { const [otp, setOtp] = useState(""); + const [timer, setTimer] = useState(30); const [isResending, setIsResending] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); @@ -27,6 +28,7 @@ export function Otp({ email }: { email: string }) { const data = await response.json(); if (response.ok) { + setTimer(30); // restart timer after resend toast("New verification code sent to your email"); } else { toast(data.message || "Failed to resend code"); @@ -77,6 +79,15 @@ export function Otp({ email }: { email: string }) { } }; + useEffect(() => { + if (timer > 0) { + const interval = setInterval(() => { + setTimer((prev) => prev - 1); + }, 1000); + return () => clearInterval(interval); + } + }, [timer]); + return (
@@ -137,10 +148,10 @@ export function Otp({ email }: { email: string }) { Didn't get a code?{" "}