"use client"; import React, { useMemo, useState } from "react"; import { useAuth } from "@/hooks/useAuth"; import { apiFetch } from "@/lib/api"; import { useDismissingState } from "@/hooks/useDismissingState"; import { useRouter } from "next/navigation"; export default function ResetPasswordPage() { const { token } = useAuth(); const router = useRouter(); const [current, setCurrent] = useState(""); const [password, setPassword] = useState(""); const [confirm, setConfirm] = useState(""); const [status, setStatus] = useState(null); const [error, setError] = useDismissingState(null); const [loading, setLoading] = useState(false); const canSubmit = useMemo(() => current.length > 0 && password.length >= 8 && password === confirm, [current, password, confirm]); const submit = async (e: React.FormEvent) => { e.preventDefault(); setStatus(null); setError(null); if (!token) { setError("You must be logged in to change your password."); return; } if (!canSubmit) return; try { setLoading(true); await apiFetch("/api/users/profile", { method: "PUT", authToken: token, body: { password, currentPassword: current } }); setStatus("Your password has been updated successfully."); setCurrent(""); setPassword(""); setConfirm(""); setTimeout(() => router.push("/dashboard/user"), 1200); } catch (err: any) { setError(err?.message || "Failed to update password"); } finally { setLoading(false); } }; return (

Reset password

{error &&

{error}

} {status &&

{status}

}
setCurrent(e.target.value)} required className="w-full border rounded px-3 py-2" placeholder="Enter your current password" />

For your security, please confirm your current password.

setPassword(e.target.value)} required className="w-full border rounded px-3 py-2" placeholder="At least 8 characters" />
setConfirm(e.target.value)} required className="w-full border rounded px-3 py-2" /> {password && confirm && password !== confirm && (

Passwords do not match.

)}
); }