mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 13:40:13 +01:00
Fix logout so it deletes token in database
This commit is contained in:
@@ -4,18 +4,17 @@ function deleteCookie(name: string): void {
|
||||
document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
|
||||
}
|
||||
|
||||
function logoutUser(): void {
|
||||
// Inform backend to remove cookie if necessary
|
||||
fetch('/api/logout', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
}).catch((err) => console.warn('Logout request failed:', err));
|
||||
async function logoutUser(): Promise<void> {
|
||||
await fetch("/api/auth/logout", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
// Clear the auth cookie
|
||||
deleteCookie('token');
|
||||
deleteCookie('token');
|
||||
|
||||
// Redirect to login page
|
||||
window.location.href = 'index.html';
|
||||
window.location.href = "/index.html";
|
||||
}
|
||||
|
||||
function redirectToLogin(): void {
|
||||
@@ -46,7 +45,10 @@ function setupAuthUI(): void {
|
||||
|
||||
if (logoutBtn) {
|
||||
logoutBtn.classList.toggle('d-none', !isAuthenticated);
|
||||
logoutBtn.addEventListener('click', logoutUser);
|
||||
logoutBtn.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
logoutUser();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user