import { useState, useEffect } from 'react'; import { useSearchParams, useNavigate, Link } from 'react-router-dom'; export default function ResetPassword() { const [searchParams] = useSearchParams(); const token = searchParams.get('token'); const navigate = useNavigate(); const [password, setPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [loading, setLoading] = useState(false); const [message, setMessage] = useState(null); const [error, setError] = useState(null); useEffect(() => { if (!token) { setError('Invalid or expired reset token. Please request a new link.'); } }, [token]); const handleReset = async (e) => { e.preventDefault(); if (!password || !token) return; setLoading(true); setError(null); try { const res = await fetch('/api/auth/reset-password', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token, new_password: password }) }); const data = await res.json(); if (!res.ok) { let errorMsg = 'Password reset failed'; if (data.detail) { if (typeof data.detail === 'string') { errorMsg = data.detail; } else if (Array.isArray(data.detail)) { errorMsg = data.detail.map((err) => err.msg).join(', '); } else { errorMsg = JSON.stringify(data.detail); } } throw new Error(errorMsg); } setMessage('Password successfully updated! Redirecting to sign in...'); setTimeout(() => navigate('/login'), 2000); } catch (err) { setError(err.message); } finally { setLoading(false); } }; return (
Choose a robust password to ensure the continued security of your financial and tax documents.
Enter your new credentials below
{error && (