Fix issue with QR code login and caching. Update README

This commit is contained in:
Ettore
2026-05-10 16:22:31 +02:00
parent a5470544a1
commit c4355eb371
3 changed files with 60 additions and 10 deletions

View File

@@ -215,15 +215,18 @@ document.getElementById("logout-btn").addEventListener("click", () => {
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ code: k.toUpperCase() }),
})
.then(res => res.ok ? res.json() : Promise.reject())
.then(res => res.ok ? res.json() : res.json().then(j => Promise.reject(j.detail || "Invalid keypass")))
.then(data => {
saveToken(data.token);
showGatesView();
loadGates();
})
.catch(() => {
.catch(msg => {
clearToken();
showLogin();
const errEl = document.getElementById("login-error");
errEl.textContent = typeof msg === "string" ? msg : "QR code login failed";
errEl.classList.remove("hidden");
});
return;
}

View File

@@ -1,6 +1,6 @@
/* Service worker - Lagomare Gates */
const CACHE = "lagomare-gates-v1";
const PRECACHE = ["/", "/static/style.css", "/static/app.js", "/static/logo.svg", "/static/mobile_icon.png", "/manifest.json"];
const PRECACHE = ["/static/style.css", "/static/app.js", "/static/logo.svg", "/static/mobile_icon.png", "/manifest.json"];
self.addEventListener("install", event => {
event.waitUntil(
@@ -20,6 +20,10 @@ self.addEventListener("fetch", event => {
// Let API calls always go to the network
if (event.request.url.includes("/api/")) return;
// Navigation requests (page loads, QR code opens) must always hit the network
// so query parameters like ?k=CODE are preserved for app.js
if (event.request.mode === "navigate") return;
event.respondWith(
caches.match(event.request).then(cached => cached || fetch(event.request))
);