import React, { useState } from 'react'; import { Link, useSearchParams, useNavigate } from 'react-router-dom'; import api from '../../api'; const ResetPasswordPage = () => { const [searchParams] = useSearchParams(); const token = searchParams.get('token'); const navigate = useNavigate(); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [error, setError] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!token) { setError('Invalid reset link. Please request a new one.'); return; } if (password.length < 8) { setError('Password must be at least 8 characters long.'); return; } if (password !== confirmPassword) { setError('Passwords do not match.'); return; } setIsSubmitting(true); setError(''); try { await api.post('/auth/reset-password', { token, new_password: password }); alert('Password has been successfully reset. You can now log in with your new password.'); navigate('/login'); } catch (err: any) { setError(err.response?.data?.error || 'Something went wrong. Please try again.'); } finally { setIsSubmitting(false); } }; if (!token) { return (

Invalid Link

This password reset link is invalid or has expired.

Request a new link
); } return ( <>

Set new password

Choose a new, strong password for your account.

{error &&
{error}
}
setPassword(e.target.value)} autoComplete="new-password" required disabled={isSubmitting} />
setConfirmPassword(e.target.value)} autoComplete="new-password" required disabled={isSubmitting} />
); }; export default ResetPasswordPage;