Update getUSer function

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