import React, { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useAuth } from '../contexts/AuthContext'; import { EyeIcon, EyeSlashIcon } from '@heroicons/react/24/outline'; import LoadingSpinner from '../components/LoadingSpinner'; const Login = () => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const { login } = useAuth(); const navigate = useNavigate(); const handleSubmit = async (e) => { e.preventDefault(); setLoading(true); setError(''); // Clear previous errors try { const result = await login(email, password); if (result.success) { // Add a small delay to ensure the user sees the success message setTimeout(() => { navigate('/dashboard'); }, 100); } else { setError(result.error || 'Login failed'); console.error('Login failed:', result.error); } } catch (error) { setError('An unexpected error occurred'); console.error('Login error:', error); } finally { setLoading(false); } }; return (
Manage your courses and track your progress