From 6e01fca87dfe6fbb7c65c9f5b30e1b5bcb2d0d5b Mon Sep 17 00:00:00 2001 From: T'JAMPENS QUENTIN p2406187 Date: Sat, 15 Nov 2025 23:28:01 +0100 Subject: [PATCH] Update getUSer function --- src/utils/getUser.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/utils/getUser.js b/src/utils/getUser.js index 5345926..6826525 100644 --- a/src/utils/getUser.js +++ b/src/utils/getUser.js @@ -1,12 +1,21 @@ export default async function getUser() { - await fetch('http://localhost:8000/api/me', { - method: 'GET', - credentials: 'include', - headers: { - 'Accept': 'application/json' + try { + const res = await fetch('http://localhost:8000/api/me', { + method: 'GET', + credentials: 'include', + headers: { + 'Accept': 'application/json' + } + }); + + if (!res.ok) { + throw new Error(`Erreur serveur : ${res.status}`); } - }) - .then(res => res.json()) - .then(data => console.log('Utilisateur connecté :', data)) - .catch(err => console.error('Erreur :', err)); -} \ No newline at end of file + + const data = await res.json(); + return data; + } catch (err) { + console.error('Erreur :', err); + return null; + } +}