Revert "hehe 3"

This reverts commit bebed1f788.
This commit is contained in:
2026-05-09 01:18:08 +01:00
parent bebed1f788
commit 1789fd7625
3 changed files with 7 additions and 25 deletions

View File

@@ -33,7 +33,6 @@
async function authFetch(input, options = {}) {
const response = await fetch(input, {
...options,
credentials: options.credentials || "same-origin",
headers: authHeaders(options.headers),
});
@@ -48,7 +47,6 @@
async function login(username, password) {
const response = await fetch("/api/auth/login", {
method: "POST",
credentials: "same-origin",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password }),
});
@@ -62,18 +60,6 @@
return data.token;
}
async function hasServerSession() {
if (token()) return true;
const response = await fetch("/api/auth/check", {
method: "GET",
credentials: "same-origin",
cache: "no-store",
});
return response.status === 204;
}
function initLoginForm() {
const form = document.getElementById("login-form");
if (!form) return;
@@ -105,19 +91,15 @@
fetch: authFetch,
headers: authHeaders,
token,
logout: async () => {
await fetch("/api/auth/logout", {
method: "POST",
credentials: "same-origin",
}).catch(() => {});
logout: () => {
window.localStorage.removeItem(TOKEN_KEY);
redirectToLogin();
},
};
document.addEventListener("DOMContentLoaded", async () => {
document.addEventListener("DOMContentLoaded", () => {
initLoginForm();
if (!isLoginPage() && !(await hasServerSession())) {
if (!isLoginPage() && !token()) {
redirectToLogin();
}
});