fix: login — setUser après auth pour maj header immédiate
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 24s

This commit is contained in:
2026-03-15 01:57:41 +01:00
parent 2c3d9d95c6
commit 6877db3227

View File

@@ -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.');