"use client"; import { useState } from "react"; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Field, FieldDescription, FieldGroup, FieldLabel, } from "@/components/ui/field"; import { Input } from "@/components/ui/input"; import { authClient } from "@/lib/auth-session/auth-client"; import { toast } from "sonner"; export function ForgotPasswordForm({ className, ...props }: React.ComponentProps<"div">) { const [email, setEmail] = useState(""); const [isLoading, setIsLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); try { const { error } = await authClient.forgetPassword({ email, redirectTo: `${window.location.origin}/reset-password`, }); if (error) { toast.error("Failed to send reset link", { description: error.message || "Please try again.", }); } else { toast.success("Password reset link sent!", { description: "Please check your email inbox.", }); setEmail(""); // Clear the form on success } } catch { toast.error("An unexpected error occurred", { description: "Please try again later.", }); } finally { setIsLoading(false); } }; return (
Forgot Password Enter your email address and we'll send you a link to reset your password
Email setEmail(e.target.value)} disabled={isLoading} required /> Remember your password?{" "} Sign in
); }