summaryrefslogtreecommitdiff
path: root/src/ollama_web/static/login.js
blob: 648e219737cc2400db8336b3874d4c32a2e23325 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"use strict";

const form = document.getElementById("login-form");
const pinInput = document.getElementById("pin-input");
const errorEl = document.getElementById("login-error");

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 = "PINが違います";
    return;
  }
  const next = new URLSearchParams(window.location.search).get("next") || "/";
  window.location.assign(next.startsWith("/") ? next : "/");
});