"use client"; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"; import { toast } from "sonner"; import { useState } from "react"; import { Loader2 } from "lucide-react"; import Link from "next/link"; import { authClient } from "@/lib/auth-session/auth-client"; import { useRouter, useSearchParams } from "next/navigation"; export function ResetPasswordForm({ className, ...props }: React.ComponentProps<"div">) { const searchParams = useSearchParams(); const router = useRouter(); const token = searchParams.get("token"); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [showPassword, setShowPassword] = useState(false); const [showConfirm, setShowConfirm] = useState(false); const [isLoading, setIsLoading] = useState(false); function togglePassword(e: React.MouseEvent) { e.preventDefault(); setShowPassword((s) => !s); } function toggleConfirm(e: React.MouseEvent) { e.preventDefault(); setShowConfirm((s) => !s); } async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setIsLoading(true); if (!token) { toast.error("Invalid or missing reset token"); setIsLoading(false); return; } if (password.length < 8) { toast.error("Password must be at least 8 characters"); setIsLoading(false); return; } if (password !== confirmPassword) { toast.error("Passwords do not match"); setIsLoading(false); return; } const { error } = await authClient.resetPassword({ newPassword: password, token, }); if (error) { toast.error(error.message || "Failed to reset password"); } else { toast.success("Password reset successfully"); router.push("/sign-in"); } setIsLoading(false); } return (
Reset Password Enter your new password
Password
setPassword(e.target.value)} placeholder="Enter your new password" disabled={isLoading} minLength={8} required />

Must be at least 8 characters

Confirm Password
setConfirmPassword(e.target.value)} placeholder="Confirm your new password" disabled={isLoading} minLength={8} required />
Don't have an account?{" "} Sign up
By clicking continue, you agree to our{" "} Terms of Service and{" "} Privacy Policy.
); }