'use client' import { useState } from 'react' import { useRouter, useSearchParams } from 'next/navigation' import Link from 'next/link' export default function ResetPasswordPage() { const router = useRouter() const searchParams = useSearchParams() const [password, setPassword] = useState('') const [confirm, setConfirm] = useState('') const [loading, setLoading] = useState(false) const [error, setError] = useState(null) async function handleSubmit(e: React.FormEvent) { e.preventDefault() setError(null) if (password.length < 8) { setError('Password must be at least 8 characters.') return } if (password !== confirm) { setError('Passwords do not match.') return } setLoading(true) const res = await fetch('/api/auth/reset-confirm', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token: searchParams.get('token'), password }), }) setLoading(false) if (res.ok) { router.push('/login?reset=success') } else { const data = await res.json() setError(data.error ?? 'Reset failed') } } return (

Set new password

Choose a strong password.

{error && (

{error}{' '} {error.includes('expired') && ( Request new link )}

)} setPassword(e.target.value)} required minLength={8} autoComplete="new-password" className="border border-gray-300 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" /> setConfirm(e.target.value)} required autoComplete="new-password" className="border border-gray-300 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" />
) }