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
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 24s
This commit is contained in:
@@ -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.');
|
||||
|
||||
Reference in New Issue
Block a user