Add QR Code for Keypasses

This commit is contained in:
Ettore
2026-05-10 00:41:36 +02:00
parent 0cb35a30cb
commit ff097b31d1
6 changed files with 107 additions and 3 deletions

View File

@@ -204,6 +204,30 @@ document.getElementById("logout-btn").addEventListener("click", () => {
// ── Init ──────────────────────────────────────────────────────────────────────
(function init() {
// Auto-login when the URL contains ?k=CODE (e.g. scanned from a QR code)
const params = new URLSearchParams(window.location.search);
const k = params.get("k");
if (k) {
// Remove the code from the URL immediately so it doesn't linger in history
history.replaceState(null, "", window.location.pathname);
fetch("/api/auth/keypass", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ code: k.toUpperCase() }),
})
.then(res => res.ok ? res.json() : Promise.reject())
.then(data => {
saveToken(data.token);
showGatesView();
loadGates();
})
.catch(() => {
clearToken();
showLogin();
});
return;
}
const t = getToken();
if (tokenValid(t)) {
showGatesView();