import React, { useState } from 'react'; import { useNavigate } from 'react-router-dom'; // Import useNavigate import { signInWithEmailAndPassword } from 'firebase/auth'; import { auth } from '../firebase'; const LoginPage = () => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const navigate = useNavigate(); // Get the navigation function const handleLogin = async () => { console.log('Attempting login...'); console.log('Email:', email); console.log('Password:', password); if (password.length < 8) { setError('The password should be minimum 8 digits'); console.log('Error:', 'The password should be minimum 8 digits'); return; } try { await signInWithEmailAndPassword(auth, email, password); console.log('Login successful'); navigate('/dashboard'); // Redirect to the dashboard after successful login } catch (error) { setError(error.message); console.log('Error:', error.message); } }; return (
{error}
}