import { useState } from "react"; import { useNavigate, useSearchParams } from "react-router-dom"; import { Lock, ArrowRight, CheckCircle, AlertCircle, Loader2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { api } from "@/lib/api"; export default function ResetPasswordPage() { const navigate = useNavigate(); const [searchParams] = useSearchParams(); const token = searchParams.get("token") || ""; const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [isLoading, setIsLoading] = useState(false); const [isSuccess, setIsSuccess] = useState(false); const [error, setError] = useState(""); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(""); if (password !== confirmPassword) { setError("Passwords do not match."); return; } if (!token) { setError("Invalid reset link. Please request a new one."); return; } setIsLoading(true); try { await api.auth.resetPassword(token, password); setIsSuccess(true); } catch (err: unknown) { const msg = err instanceof Error ? err.message : "Failed to reset password. The link may be expired."; setError(msg); } finally { setIsLoading(false); } }; if (isSuccess) { return (

Password reset successful

Your password has been updated. You can now sign in with your new password.

); } return (

Reset your password

Enter a new password for your account

setPassword(e.target.value)} className="pl-10" required minLength={8} />

Must be at least 8 characters

setConfirmPassword(e.target.value)} className="pl-10" required />
{error && (

{error}

)}
); }