import { useState, FormEvent } from 'react'; import { useNavigate } from 'react-router-dom'; import toast from 'react-hot-toast'; import api from '../api/client'; import { useAuthStore } from '../store/auth'; export default function Login() { const navigate = useNavigate(); const { setAuth } = useAuthStore(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); async function handleSubmit(e: FormEvent) { e.preventDefault(); setLoading(true); try { const res = await api.post('/auth/login', { email, password }); setAuth(res.data.user, res.data.accessToken, res.data.refreshToken); navigate('/new', { replace: true }); } catch (err: any) { toast.error(err.response?.data?.error ?? 'Connexion impossible'); } finally { setLoading(false); } } return (
Gestion de notes de frais