fix: logout button in settings panel now properly clears session

- Both #logout-btn and #profile-logout now delegate to window.handleLogout()
- Previously they did bare fetch+redirect without clearing JWT token or session state
- Added credentials: 'include' fallback for robustness
This commit is contained in:
2026-07-24 09:27:54 -04:00
parent 797d9763dd
commit 61caa47745
+17 -10
View File
@@ -631,14 +631,17 @@ function initConfigModal() {
}); });
} }
// Logout button (always visible) // Logout button (always visible) — delegates to global handleLogout for proper session cleanup
var logoutBtn = document.getElementById("logout-btn"); var logoutBtn = document.getElementById("logout-btn");
if (logoutBtn) { if (logoutBtn) {
logoutBtn.addEventListener("click", function() { logoutBtn.addEventListener("click", function() {
if (confirm("Voulez-vous vraiment vous deconnecter ?")) { if (confirm(t('confirm.logout') || "Voulez-vous vraiment vous deconnecter ?")) {
fetch("/api/auth/logout", { method: "POST" }) if (typeof window.handleLogout === 'function') {
.then(function() { window.location.href = "/"; }) window.handleLogout();
.catch(function() { window.location.href = "/"; }); } else {
fetch('/api/auth/logout', { method: 'POST', credentials: 'include' })
.finally(function() { window.location.href = '/'; });
}
} }
}); });
} }
@@ -1576,13 +1579,17 @@ function initProfile() {
} catch(e) {} } catch(e) {}
}); });
// Logout button // Logout button — delegates to global handleLogout for proper session cleanup
if (logoutBtn) { if (logoutBtn) {
logoutBtn.addEventListener('click', function() { logoutBtn.addEventListener('click', function() {
if (confirm(t('confirm.logout'))) { if (confirm(t('confirm.logout') || 'Voulez-vous vraiment vous deconnecter ?')) {
fetch('/api/auth/logout', { method: 'POST' }) if (typeof window.handleLogout === 'function') {
.then(function() { window.location.href = '/'; }) window.handleLogout();
.catch(function() { window.location.href = '/'; }); } else {
// Fallback if handleLogout not loaded
fetch('/api/auth/logout', { method: 'POST', credentials: 'include' })
.finally(function() { window.location.href = '/'; });
}
} }
}); });
} }