"use client"; import Link from "next/link"; import { useRouter, useSearchParams } from "next/navigation"; import { Suspense, useState } from "react"; import { Background } from "../../components/background"; import { SiteFooter } from "../../components/site-footer"; import { SiteHeader } from "../../components/site-header"; type ApiResponse = { data: T; meta: { timestamp: string; version: "v1" }; error: null | { message: string; code?: string }; }; function ResetPasswordForm() { const router = useRouter(); const searchParams = useSearchParams(); const token = searchParams.get("token") ?? ""; const [password, setPassword] = useState(""); const [confirm, setConfirm] = useState(""); const [status, setStatus] = useState(""); const [isError, setIsError] = useState(false); const onSubmit = async (event: React.FormEvent) => { event.preventDefault(); if (password !== confirm) { setStatus("Passwords do not match."); setIsError(true); return; } if (password.length < 8) { setStatus("Password must be at least 8 characters."); setIsError(true); return; } if (!token) { setStatus("Missing reset token. Please use the link from your email."); setIsError(true); return; } setStatus("Resetting password..."); setIsError(false); try { const res = await fetch("/api/auth/reset-password", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token, password }), }); const payload = (await res.json()) as ApiResponse<{ message: string }>; if (!res.ok || payload.error) { setStatus(payload.error?.message ?? "Reset failed. The link may have expired."); setIsError(true); return; } setStatus("Password reset successfully! Redirecting to sign in..."); setTimeout(() => router.push("/login"), 2000); } catch { setStatus("Something went wrong. Please try again."); setIsError(true); } }; if (!token) { return (

Invalid reset link. Please request a new one.

Request password reset
); } return (
setPassword(e.target.value)} className="block w-full appearance-none rounded-lg border border-border bg-background/50 px-3 py-2 text-foreground placeholder-muted-foreground shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20 sm:text-sm transition-all" />

Minimum 8 characters

setConfirm(e.target.value)} className="block w-full appearance-none rounded-lg border border-border bg-background/50 px-3 py-2 text-foreground placeholder-muted-foreground shadow-sm focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20 sm:text-sm transition-all" />
{status && (

{status}

)}
); } export default function ResetPasswordPage() { return (
L1

Set new password

Back to sign in

Loading...
}>
); }