fix: persist admin sessions across restart

This commit is contained in:
Андрей Бобырев
2026-06-06 15:44:45 +03:00
parent 76201b6b2a
commit caee0b4cff
3 changed files with 30 additions and 5 deletions

View File

@@ -636,6 +636,10 @@ async function api(path, options = {}) {
if (options.body && !headers["Content-Type"]) headers["Content-Type"] = "application/json";
const res = await fetch(path, { ...options, headers, credentials: "same-origin" });
const data = await res.json().catch(() => ({}));
if (res.status === 401) {
window.location.assign("/");
throw new Error("unauthorized");
}
if (!res.ok || data.ok === false) throw new Error(data.error || `HTTP ${res.status}`);
return data.data ?? data;
}