Update getUSer function
This commit is contained in:
+14
-5
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user