add a login and encrypt the .env so people can't get in and still the api key

This commit is contained in:
rainyy21
2026-11-11 17:01:25 -05:00
parent f662e647d7
commit 96e608126b
10 changed files with 422 additions and 72 deletions
+2
View File
@@ -76,6 +76,7 @@ const api = (path, opts = {}) => fetch(path, {
...opts,
headers: { "X-CSRF-Token": CSRF, "Content-Type": "application/json", ...(opts.headers || {}) },
}).then(async res => {
if (res.status === 401) { location.reload(); throw new Error("logged out"); } // -> login page
const data = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(data.error || `request failed (${res.status})`);
return data;
@@ -332,6 +333,7 @@ document.addEventListener("click", async e => {
if (document.hidden) return;
try {
const res = await fetch("/api/version", { cache: "no-store" });
if (res.status === 401 && !anyOpen()) location.reload(); // session expired -> login page
if (!res.ok) return;
const { version } = await res.json();
if (seen === null) seen = version;