This commit is contained in:
Mateusz Gruszczyński committed 2026-10-04 16:47:24 +02:00
1 parent 59ddabb72b
commit 174389e5b1
48 files changed
+688 -212

No files matched your search

+19 -1
View File
@@ -3,6 +3,23 @@ const $ = (id) => document.getElementById(id);
let language = null;
try { language = localStorage.getItem("rp-language"); } catch { }
let csrf = "", authenticated = false, setupRequired = false, sessionInfo = null;
const ORIGIN_RECOVERY_KEY = "rp-origin-recovery-v1";
function recoverInvalidOrigin(error) {
if (error?.code !== "auth.invalid_origin" || typeof location === "undefined") return false;
const marker = `${location.origin}${location.pathname}${location.search}`;
try {
if (sessionStorage.getItem(ORIGIN_RECOVERY_KEY) === marker) return false;
sessionStorage.setItem(ORIGIN_RECOVERY_KEY, marker);
} catch {
if (recoverInvalidOrigin.attempted) return false;
recoverInvalidOrigin.attempted = true;
}
location.reload();
return true;
}
function clearInvalidOriginRecovery() {
try { sessionStorage.removeItem(ORIGIN_RECOVERY_KEY); } catch { recoverInvalidOrigin.attempted = false; }
}
const ADMIN_THEMES = new Set(["dark", "light"]);
let adminPreferences = null, adminPreferencesLoading = null, adminPreferencesWrite = Promise.resolve();
function normalizeAdminTheme(value) { return ADMIN_THEMES.has(value) ? value : "dark"; }
@@ -400,10 +417,11 @@ async function revalidateSession() {
const epoch = authEpoch;
try {
const info = await api("/api/auth/session");
clearInvalidOriginRecovery();
if (epoch !== authEpoch) return;
if (!authenticated) { await activate(info); return; }
sessionInfo = info; csrf = info.csrf_token; renderSession(); await refresh(true); startLive();
} catch (error) { if (error.status !== 401) toast(error.message, true); }
} catch (error) { if (recoverInvalidOrigin(error)) return; if (error.status !== 401) toast(error.message, true); }
}
window.addEventListener("pageshow", event => { if (event.persisted) void revalidateSession(); });
document.addEventListener("visibilitychange", () => { if (document.hidden) stopLive(); else if (authenticated) { void revalidateSession(); } });