import React, { useState } from 'react'; import { useNavigate, useLocation } from 'react-router-dom'; import { useAuth } from '../context/useAuth'; import { Card, CardContent, CardHeader, CardTitle } 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'; const LoginPage = () => { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const { login } = useAuth(); const navigate = useNavigate(); const location = useLocation(); const from = location.state?.from?.pathname || "/"; const handleSubmit = async (e) => { e.preventDefault(); setError(''); try { await login(username, password); navigate(from, { replace: true }); } catch (err) { setError('Nom d\'utilisateur ou mot de passe incorrect'); console.error(err); } }; return (
Connexion {error && ( {error} )}
setUsername(e.target.value)} required />
setPassword(e.target.value)} required />
); }; export default LoginPage;