import { useState, useEffect } from 'react'; import { useNavigate, useLocation, Link } from 'react-router-dom'; import { useAuth } from '../context/AuthContext'; export default function Login() { const { login, currentUser } = useAuth(); const navigate = useNavigate(); const location = useLocation(); const successMessage = location.state?.message || ''; const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); useEffect(() => { if (currentUser) { navigate('/dashboard', { replace: true }); } }, [currentUser, navigate]); const handleSuccess = async (e) => { e.preventDefault(); setLoading(true); setError(''); const { error: err } = await login(email, password); if (err) { setError('Invalid email or password.'); } setLoading(false); // Navigation handled by useEffect watching currentUser }; return (
Client & Project Portal
Contact Fourge Branding to get access.