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;
+11 -2
View File
@@ -154,12 +154,12 @@
.field .hint { font-size: 11.5px; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input[type=text], select {
input[type=text], input[type=password], select {
font: inherit; font-size: 13px; color: var(--text);
background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
padding: 8px 10px; width: 100%;
}
input[type=text]:focus, select:focus { outline: none; border-color: var(--accent); }
input[type=text]:focus, input[type=password]:focus, select:focus { outline: none; border-color: var(--accent); }
input.invalid { border-color: var(--error); }
.check { display: flex; align-items: flex-start; gap: 10px; font-size: 13px; cursor: pointer; }
@@ -331,3 +331,12 @@ span.commit:hover { text-decoration: none; }
@keyframes blink { 50% { opacity: 0; } }
.editor-loading { padding: 16px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .cursor { animation: none; } }
/* ---------- login ---------- */
.login { min-height: calc(100vh - 88px); display: flex; align-items: center; justify-content: center; }
.login .modal { max-width: 360px; }
.login .modal-head { color: var(--accent); }
.login .modal-foot .btn { width: 100%; }
.login-error { color: var(--error); font-size: 13px; }
.login-note { color: var(--warn); font-size: 12.5px; }
.logout { display: contents; }