Update getUSer function

This commit is contained in:
T'JAMPENS QUENTIN p2406187
2025-11-15 23:28:01 +01:00
parent 7e3c60825a
commit 6e01fca87d
+19 -10
View File
@@ -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));
}
const data = await res.json();
return data;
} catch (err) {
console.error('Erreur :', err);
return null;
}
}