feat: profile avatar, callback setUser fix, admin description/thumbnail, pagination limit=100
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 26s
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 26s
This commit is contained in:
@@ -1,29 +1,38 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { apiFetch } from '../lib/api';
|
||||
import { useAuthContext } from '../context/AuthContext';
|
||||
import type { User } from '../context/AuthContext';
|
||||
|
||||
interface SessionResponse {
|
||||
success: boolean;
|
||||
data: { user: User };
|
||||
}
|
||||
|
||||
export default function CallbackPage() {
|
||||
const navigate = useNavigate();
|
||||
const { setUser } = useAuthContext();
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const token = params.get('token');
|
||||
|
||||
// Pas de token dans l'URL → retour silencieux
|
||||
if (!token) {
|
||||
navigate('/', { replace: true });
|
||||
return;
|
||||
}
|
||||
|
||||
// Envoie le token au backend → backend valide + pose le cookie httpOnly
|
||||
apiFetch<void>('/auth/session', {
|
||||
apiFetch<SessionResponse>('/auth/session', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ token }),
|
||||
})
|
||||
.then(() => navigate('/', { replace: true }))
|
||||
.then((res) => {
|
||||
setUser(res.data.user);
|
||||
navigate('/', { replace: true });
|
||||
})
|
||||
.catch(() => setError("Échec de l'authentification. Réessaie."));
|
||||
}, [navigate]);
|
||||
}, [navigate, setUser]);
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user