blob: 41169cb076e09f469c3fea23e7934822384e6b6b (
plain) (
tree)
|
|
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
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();
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 (
<div className="container mx-auto flex items-center justify-center min-h-screen bg-gray-100">
<div className="bg-white p-6 rounded shadow-md w-full max-w-sm">
<h4 className="mb-4 text-center">Login</h4>
<div className="mb-4">
<label>Email</label>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
className="form-control"
/>
</div>
<div className="mb-4">
<label>Password</label>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
className="form-control"
/>
</div>
{error && <p className="text-danger">{error}</p>}
<button onClick={handleLogin} className="btn btn-primary w-full mb-2">Login</button>
<button onClick={() => navigate('/reset')} className="btn btn-secondary w-full">Reset Password</button>
</div>
</div>
);
};
export default LoginPage;
|