[fix](trx-frontend-http): prevent browser hang on logout
Replace location.reload() with disconnect() + auth gate to prevent browser hang when logging out. The full page reload was causing issues with resource loading and event source reconnection timers. Changes: - Add disconnect() function to cleanly close EventSource connections and clear all timers (esHeartbeat, reconnectTimer) - authLogout() now disconnects locally and shows auth gate instead of reloading the page - Faster logout experience without full page reload Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
@@ -48,9 +48,14 @@ async function authLogout() {
|
|||||||
const resp = await fetch("/auth/logout", { method: "POST" });
|
const resp = await fetch("/auth/logout", { method: "POST" });
|
||||||
if (!resp.ok) throw new Error("Logout failed");
|
if (!resp.ok) throw new Error("Logout failed");
|
||||||
authRole = null;
|
authRole = null;
|
||||||
location.reload();
|
// Disconnect and show auth gate without page reload
|
||||||
|
disconnect();
|
||||||
|
document.getElementById("content").style.display = "none";
|
||||||
|
updateAuthUI();
|
||||||
|
showAuthGate(false);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Logout failed:", e);
|
console.error("Logout failed:", e);
|
||||||
|
showAuthError("Logout failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -909,6 +914,27 @@ function connect() {
|
|||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function disconnect() {
|
||||||
|
// Close event sources
|
||||||
|
if (es) {
|
||||||
|
es.close();
|
||||||
|
es = null;
|
||||||
|
}
|
||||||
|
if (decodeSource) {
|
||||||
|
decodeSource.close();
|
||||||
|
decodeSource = null;
|
||||||
|
}
|
||||||
|
// Clear timers
|
||||||
|
if (esHeartbeat) {
|
||||||
|
clearInterval(esHeartbeat);
|
||||||
|
esHeartbeat = null;
|
||||||
|
}
|
||||||
|
if (reconnectTimer) {
|
||||||
|
clearTimeout(reconnectTimer);
|
||||||
|
reconnectTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function postPath(path) {
|
async function postPath(path) {
|
||||||
const resp = await fetch(path, { method: "POST" });
|
const resp = await fetch(path, { method: "POST" });
|
||||||
if (resp.status === 401 || resp.status === 403) {
|
if (resp.status === 401 || resp.status === 403) {
|
||||||
|
|||||||
Reference in New Issue
Block a user