"use client"; import dynamic from "next/dynamic"; import Link from "next/link"; import { useState } from "react"; import { useRouter, useSearchParams } from "next/navigation"; const labelCls = "flex flex-col gap-[0.35rem] text-[0.9rem] font-semibold text-[#444]"; const inputCls = "px-[0.85rem] py-[0.6rem] border border-[#ddd] rounded-lg text-base outline-none transition-all focus:border-[#e68672] focus:shadow-[0_0_0_3px_rgba(230,134,114,0.2)]"; const submitBtnCls = "mt-2 py-3 bg-[#e68672] text-white border-none rounded-lg text-base font-bold cursor-pointer transition-all hover:bg-[#d4705e] active:scale-[0.98] disabled:opacity-60 disabled:cursor-not-allowed"; function ResetPasswordPage() { const router = useRouter(); const searchParams = useSearchParams(); const token = searchParams.get("token") || ""; const [newPassword, setNewPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(false); if (!token) { return (

Invalid Link

This password reset link is missing or invalid. Please request a new one.

Request a new reset link

); } async function handleSubmit(e) { e.preventDefault(); setError(""); if (newPassword !== confirmPassword) { setError("Passwords do not match."); return; } setLoading(true); try { const res = await fetch("/api/v1/auth/reset-password", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token, newPassword }), }); const data = await res.json(); if (!res.ok) { throw new Error(data.message || "Failed to reset password. The link may have expired."); } setSuccess(true); setTimeout(() => router.push("/login"), 3000); } catch (err) { setError(err.message); } finally { setLoading(false); } } if (success) { return (

Password Reset

Your password has been reset successfully. Redirecting you to login…

Go to login

); } return (

Reset Password

{error &&

{error}

}

Remember your password?{" "} Log in here

); } export default dynamic(() => Promise.resolve(ResetPasswordPage), { ssr: false, });