From 61caa47745668d256721e359474c357bca414676 Mon Sep 17 00:00:00 2001 From: bruno Date: Fri, 24 Jul 2026 09:27:54 -0400 Subject: [PATCH] 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 --- frontend/js/config.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/frontend/js/config.js b/frontend/js/config.js index 8a458f4..02e4664 100644 --- a/frontend/js/config.js +++ b/frontend/js/config.js @@ -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"); if (logoutBtn) { logoutBtn.addEventListener("click", function() { - if (confirm("Voulez-vous vraiment vous deconnecter ?")) { - fetch("/api/auth/logout", { method: "POST" }) - .then(function() { window.location.href = "/"; }) - .catch(function() { window.location.href = "/"; }); + if (confirm(t('confirm.logout') || "Voulez-vous vraiment vous deconnecter ?")) { + if (typeof window.handleLogout === 'function') { + window.handleLogout(); + } else { + fetch('/api/auth/logout', { method: 'POST', credentials: 'include' }) + .finally(function() { window.location.href = '/'; }); + } } }); } @@ -1576,13 +1579,17 @@ function initProfile() { } catch(e) {} }); - // Logout button + // Logout button — delegates to global handleLogout for proper session cleanup if (logoutBtn) { logoutBtn.addEventListener('click', function() { - if (confirm(t('confirm.logout'))) { - fetch('/api/auth/logout', { method: 'POST' }) - .then(function() { window.location.href = '/'; }) - .catch(function() { window.location.href = '/'; }); + if (confirm(t('confirm.logout') || 'Voulez-vous vraiment vous deconnecter ?')) { + if (typeof window.handleLogout === 'function') { + window.handleLogout(); + } else { + // Fallback if handleLogout not loaded + fetch('/api/auth/logout', { method: 'POST', credentials: 'include' }) + .finally(function() { window.location.href = '/'; }); + } } }); }