import { useState } from 'react'; import { useNavigate, useLocation } from 'react-router-dom'; import { useMutation } from '@tanstack/react-query'; import { motion } from 'framer-motion'; import { authApi } from '../api/auth'; import { ApiError } from '../api/client'; import { useAuthStore } from '../stores/authStore'; import { AuthShell } from '../components/AuthShell'; export function LoginPage() { const navigate = useNavigate(); const location = useLocation(); const setUser = useAuthStore((state) => state.setUser); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const flashMessage = (location.state as { message?: string } | null)?.message; const loginMutation = useMutation({ mutationFn: authApi.login, onSuccess: (data) => { setUser(data.user); navigate('/'); }, onError: (err: Error) => { setError(err instanceof ApiError ? err.message : 'Échec de la connexion. Veuillez réessayer.'); }, }); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); setError(''); loginMutation.mutate({ email, password }); }; return (
{flashMessage && !error && (

{flashMessage}

)} {error && (

{error}

)}
setEmail(e.target.value)} className="input-field" placeholder="vous@exemple.com" required autoFocus />
setPassword(e.target.value)} className="input-field" placeholder="••••••••" required />
{loginMutation.isPending ? 'Authentification…' : 'Continuer'}

Nouveau chez FlowReader ?{' '}

); }