Add logout btn

This commit is contained in:
T'JAMPENS QUENTIN p2406187
2025-12-04 18:18:31 +01:00
parent 37e4968023
commit 22065fbd16
5 changed files with 48 additions and 7 deletions
+28
View File
@@ -0,0 +1,28 @@
import getXSRFToken from "../getXSRF.js";
export default async function logout() {
const csrfToken = await getXSRFToken();
try {
const response = await fetch(`http://${import.meta.env.VITE_API_URL}/api/users/logout`, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-XSRF-TOKEN': csrfToken
},
});
console.log('Code HTTP :', response.status);
if (!response.ok) {
throw new Error(`Erreur HTTP ${response.status}`);
}
return { status: response.status };
} catch (error) {
return error;
}
}