"use client"; import * as React from "react"; import Link from "next/link"; import { authClient } from "@/lib/auth-client"; import { AuthCard } from "@/components/auth/auth-card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Field, Label } from "@/components/ui/label"; import { Alert } from "@/components/ui/alert"; export default function ForgotPasswordPage() { const [email, setEmail] = React.useState(""); const [sent, setSent] = React.useState(false); const [loading, setLoading] = React.useState(false); const [error, setError] = React.useState(null); async function onSubmit(e: React.FormEvent) { e.preventDefault(); setLoading(true); setError(null); const { error } = await authClient.requestPasswordReset({ email: email.trim(), redirectTo: "/reset-password" }); setLoading(false); if (error && error.status === 429) return setError("Too many attempts. Wait a minute and try again."); setSent(true); // Always confirm to avoid leaking whether an account exists. } return ( Back to log in} > {sent ? ( If an account exists for {email}, a reset link is on its way. It expires in one hour. ) : (
{error ? {error} : null} setEmail(e.target.value)} placeholder="you@company.com" autoFocus />
)}
); }