window.getAuthToken = function () { return localStorage.getItem("knoptpq"); }; window.fetchWithAuth = async function (url, options = {}) { const token = getAuthToken(); if (!token) { window.location.href = "/client/login"; return; } const res = await fetch(url, { ...options, headers: { token, "Content-Type": "application/json", ...options.headers, }, }); if (res.status === 401) { localStorage.clear(); window.location.href = "/client/login"; return; } return res; };