"use client" import { useState, useRef } from "react" import { KeyRound, Loader2, ArrowLeft } from "lucide-react" import { authClient } from "@/lib/auth-client" import { forgotPasswordSchema, } from "@/lib/auth/validation" import TurnstileWidget, { type TurnstileWidgetHandle } from "./turnstile-widget" import Link from "next/link" import { useRouter } from "next/navigation" export default function ForgotPasswordForm() { const router = useRouter() const [email, setEmail] = useState("") const [error, setError] = useState("") const [isLoading, setIsLoading] = useState(false) const [turnstileToken, setTurnstileToken] = useState("") const turnstileRef = useRef(null) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError("") const result = forgotPasswordSchema.safeParse({ email }) if (!result.success) { setError(result.error.issues[0].message) return } setIsLoading(true) const { error } = await authClient.emailOtp.requestPasswordReset({ email, fetchOptions: { headers: { "x-captcha-response": turnstileToken, }, }, }) setIsLoading(false) if (error) { setError( error.message || "Something went wrong. Please try again.", ) turnstileRef.current?.reset() setTurnstileToken("") return } // Redirect to reset password page with email router.push(`/reset-password?email=${encodeURIComponent(email)}`) } return (

Forgot your password?

Enter your email and we'll send you a verification code to reset your password.

{error && (
{error}
)}
setEmail(e.target.value)} placeholder="you@deckyvault.xyz" className="w-full px-4 py-3 rounded-lg border border-border bg-text/5 text-text text-sm placeholder:text-text/40 outline-none focus:border-primary focus:ring-2 focus:ring-primary/50 transition-colors" />
setTurnstileToken("")} /> Back to sign in ) }