import React, { useState } from 'react'; import { useNavigate, useLocation } from 'react-router-dom'; import { useAuth } from '../context/useAuth'; import MainCard from '../components/MainCard'; import { CardContent } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Button } from '@/components/ui/button'; import { Alert, AlertDescription, } from '@/components/ui/alert'; import {KeyRound} from 'lucide-react'; const LoginPage = () => { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const { login } = useAuth(); const navigate = useNavigate(); const location = useLocation(); const from = location.state?.from?.pathname || '/'; const handleSubmit = async (e) => { e.preventDefault(); if (loading) { return; } setError(''); setLoading(true); try { await login(username, password); navigate(from, { replace: true }); } catch (err) { setError( 'Nom d\'utilisateur ou mot de passe incorrect', ); console.error(err); } finally { setLoading(false); } }; return ( {error && ( {error} )}
setUsername(e.target.value) } disabled={loading} required />
setPassword(e.target.value) } disabled={loading} required />
); }; export default LoginPage;