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