Update getUSer function

This commit is contained in:
T'JAMPENS QUENTIN p2406187
2025-11-15 23:28:01 +01:00
parent 7e3c60825a
commit 6e01fca87d
+14 -5
View File
@@ -1,12 +1,21 @@
export default async function getUser() { export default async function getUser() {
await fetch('http://localhost:8000/api/me', { try {
const res = await fetch('http://localhost:8000/api/me', {
method: 'GET', method: 'GET',
credentials: 'include', credentials: 'include',
headers: { headers: {
'Accept': 'application/json' 'Accept': 'application/json'
} }
}) });
.then(res => res.json())
.then(data => console.log('Utilisateur connecté :', data)) if (!res.ok) {
.catch(err => console.error('Erreur :', err)); throw new Error(`Erreur serveur : ${res.status}`);
}
const data = await res.json();
return data;
} catch (err) {
console.error('Erreur :', err);
return null;
}
} }