import { useState } from 'react'; import { useNavigate, useSearchParams, Link } from 'react-router-dom'; import { authAPI } from '../services/api'; import { Video, Lock, CheckCircle, XCircle, Loader2 } from 'lucide-react'; import PasswordStrengthIndicator from '../components/common/PasswordStrengthIndicator'; import PublicLayout from '../components/layout/PublicLayout'; const ResetPasswordPage = () => { const [searchParams] = useSearchParams(); const navigate = useNavigate(); const token = searchParams.get('token'); const [newPassword, setNewPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(false); const [error, setError] = useState(''); const handleSubmit = async (e) => { e.preventDefault(); setError(''); // Validation if (!token) { setError('Invalid or missing reset token'); return; } if (newPassword !== confirmPassword) { setError('Passwords do not match'); return; } if (newPassword.length < 8) { setError('Password must be at least 8 characters long'); return; } setLoading(true); try { await authAPI.resetPassword(token, newPassword); setSuccess(true); } catch (err) { setError(err.data?.error || 'Failed to reset password. The link may have expired.'); } finally { setLoading(false); } }; // Success state if (success) { return ( Password Reset Successfully! 🎉 Your password has been updated. You can now log in with your new password. navigate('/login')} className="w-full py-2 px-4 border border-transparent rounded-md shadow-sm text-white bg-primary-600 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 font-medium" > Go to Login ); } // Invalid token state if (!token) { return ( Invalid Reset Link This password reset link is invalid or has expired. Please request a new one. Request New Link ); } // Reset password form return ( Set New Password Enter your new password below {error && ( {error} )} {/* New Password */} New Password setNewPassword(e.target.value)} className="pl-10 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-primary-500 focus:border-primary-500" placeholder="••••••••" required disabled={loading} /> {/* Confirm Password */} Confirm New Password setConfirmPassword(e.target.value)} className="pl-10 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-primary-500 focus:border-primary-500" placeholder="••••••••" required disabled={loading} /> {confirmPassword && newPassword !== confirmPassword && ( Passwords do not match )} {loading ? ( <> Resetting... > ) : ( 'Reset Password' )} Back to Login ); }; export default ResetPasswordPage;
Your password has been updated. You can now log in with your new password.
This password reset link is invalid or has expired. Please request a new one.
Enter your new password below
{error}
Passwords do not match