diff --git a/frontend/src/pages/LoginPage.tsx b/frontend/src/pages/LoginPage.tsx index c83a234..25cdcf5 100644 --- a/frontend/src/pages/LoginPage.tsx +++ b/frontend/src/pages/LoginPage.tsx @@ -1,6 +1,7 @@ import { useState } from 'react'; import { Link, useNavigate, useLocation } from 'react-router-dom'; import { apiFetch } from '../lib/api'; +import { useAuthContext, type User } from '../context/AuthContext'; const PROVIDERS = [ { id: 'discord', label: 'Discord' }, @@ -12,6 +13,7 @@ const PROVIDERS = [ export default function LoginPage() { const navigate = useNavigate(); const location = useLocation(); + const { setUser } = useAuthContext(); const from = (location.state as { from?: Location })?.from?.pathname ?? '/'; const base = import.meta.env.VITE_SUPEROAUTH_URL; const redirectUrl = encodeURIComponent(window.location.origin + '/callback'); @@ -27,10 +29,11 @@ export default function LoginPage() { setLoading(true); setError(null); try { - await apiFetch('/auth/login', { + const res = await apiFetch<{ success: boolean; data: { user: User } }>('/auth/login', { method: 'POST', body: JSON.stringify({ email, password }), }); + setUser(res.data.user); navigate(from, { replace: true }); } catch { setError('Email ou mot de passe incorrect.');