refactor(auth): relocate logout handler to main.js

This commit is contained in:
Ryan
2025-04-26 04:33:01 -04:00
committed by GitHub
parent 1983f7705f
commit 0a9d332d60
3 changed files with 22 additions and 20 deletions

View File

@@ -48,6 +48,27 @@ export function loadCsrfToken() {
});
}
// 1) Immediately clear “?logout=1” flag
const params = new URLSearchParams(window.location.search);
if (params.get('logout') === '1') {
localStorage.removeItem("username");
localStorage.removeItem("userTOTPEnabled");
}
// 2) Wire up logoutBtn right away
const logoutBtn = document.getElementById("logoutBtn");
if (logoutBtn) {
logoutBtn.addEventListener("click", () => {
fetch("/api/auth/logout.php", {
method: "POST",
credentials: "include",
headers: { "X-CSRF-Token": window.csrfToken }
})
.then(() => window.location.reload(true))
.catch(() => {});
});
}
// Expose functions for inline handlers.
window.sendRequest = sendRequest;