"use client"; import { useState } from "react"; import Link from "next/link"; import { useRouter, useSearchParams } from "next/navigation"; import { Loader2 } from "lucide-react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; import { authClient } from "@/lib/auth/auth-client"; export function ResetPasswordForm() { const router = useRouter(); const params = useSearchParams(); const token = params.get("token") ?? ""; const errorParam = params.get("error"); const [loading, setLoading] = useState(false); async function onSubmit(e: React.FormEvent) { e.preventDefault(); const form = new FormData(e.currentTarget); const newPassword = String(form.get("password")); const confirm = String(form.get("confirm")); if (newPassword !== confirm) { toast.error("Passwords don't match"); return; } setLoading(true); const { error } = await authClient.resetPassword({ newPassword, token }); setLoading(false); if (error) { toast.error(error.message ?? "Could not reset password"); return; } toast.success("Password updated. Please sign in."); router.push("/sign-in"); } if (errorParam || !token) { return ( Invalid or expired link Please request a new password reset link. ); } return ( Set a new password Choose a strong password you don't use elsewhere.
); }