import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useSearchParams, useNavigate } from 'react-router-dom'; import { Helmet } from 'react-helmet-async'; import { KeyRound } from 'lucide-react'; const API_BASE = import.meta.env.VITE_API_URL || ''; export default function ResetPasswordPage() { const { t } = useTranslation(); const navigate = useNavigate(); const [searchParams] = useSearchParams(); const token = searchParams.get('token') || ''; const [password, setPassword] = useState(''); const [confirm, setConfirm] = useState(''); const [success, setSuccess] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); if (password.length < 8) { setError(t('auth.resetPassword.tooShort')); return; } if (password !== confirm) { setError(t('account.passwordMismatch')); return; } setLoading(true); try { const res = await fetch(`${API_BASE}/api/auth/reset-password`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', body: JSON.stringify({ token, password }), }); const data = await res.json(); if (!res.ok) throw new Error(data.error || 'Reset failed'); setSuccess(true); setTimeout(() => navigate('/account'), 3000); } catch (err) { setError(err instanceof Error ? err.message : t('auth.resetPassword.error')); } finally { setLoading(false); } }; if (!token) { return (

{t('auth.resetPassword.noToken')}

); } return ( <> {t('auth.resetPassword.title')} — {t('common.appName')}

{t('auth.resetPassword.title')}

{success ? (

{t('auth.resetPassword.success')}

) : (
setPassword(e.target.value)} className="w-full rounded-lg border border-slate-300 px-3 py-2 text-sm dark:border-slate-600 dark:bg-slate-700 dark:text-slate-200" />
setConfirm(e.target.value)} className="w-full rounded-lg border border-slate-300 px-3 py-2 text-sm dark:border-slate-600 dark:bg-slate-700 dark:text-slate-200" />
{error && (

{error}

)}
)}
); }