"use client" import { useEffect, useState, Suspense } from "react" import { useRouter, useSearchParams } from "next/navigation" import { Button } from "@/components/ui/button" function ResetPasswordForm() { const router = useRouter() const searchParams = useSearchParams() const token = searchParams.get("token") const email = searchParams.get("email") const [password, setPassword] = useState("") const [confirmPassword, setConfirmPassword] = useState("") const [isSubmitting, setIsSubmitting] = useState(false) const [error, setError] = useState(null) const [success, setSuccess] = useState(false) useEffect(() => { if (!token || !email) { setError("Invalid or missing reset link") } }, [token, email]) const handleSubmit = async () => { setError(null) if (!password || !confirmPassword) { setError("Please enter and confirm your new password") return } if (password.length < 8) { setError("Password must be at least 8 characters") return } if (password !== confirmPassword) { setError("Passwords do not match") return } setIsSubmitting(true) try { const res = await fetch("/api/auth/reset-password", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token, email, password }), }) const data = await res.json() if (!res.ok) { setError(data.error || "Failed to reset password") return } setSuccess(true) // Redirect to login after 3 seconds setTimeout(() => { router.push("/login") }, 3000) } catch { setError("Failed to reset password") } finally { setIsSubmitting(false) } } if (success) { return (

Password Reset!

Your password has been successfully reset.

Redirecting to login...

) } return (

Reset Password

Enter your new password below.

{error && (

{error}

)}
setPassword(e.target.value)} className="w-full px-3 py-2 bg-slate-800 border border-slate-700 rounded-lg text-white" placeholder="At least 8 characters" />
setConfirmPassword(e.target.value)} className="w-full px-3 py-2 bg-slate-800 border border-slate-700 rounded-lg text-white" placeholder="Re-enter password" />
) } export default function ResetPasswordPage() { return (

Loading...

}>
) }