blob: 4c9151b422c058cba7e640cd466afa61273f7745 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
"use strict";
const form = document.getElementById("login-form");
const pinInput = document.getElementById("pin-input");
const errorEl = document.getElementById("login-error");
const ALLOWED_NEXT_PATHS = new Set(["/", "/chat", "/settings"]);
form.addEventListener("submit", async (event) => {
event.preventDefault();
errorEl.textContent = "";
const res = await fetch("/api/auth/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ pin: pinInput.value }),
});
if (!res.ok) {
errorEl.textContent = t("login.pin_invalid", "Invalid PIN");
return;
}
const requestedNext = new URLSearchParams(window.location.search).get("next") || "/";
const safeNext = ALLOWED_NEXT_PATHS.has(requestedNext) ? requestedNext : "/";
window.location.assign(safeNext);
});
|