Keyborg/server/src/js/login.ts
2025-02-13 18:31:44 +03:00

24 lines
622 B
TypeScript

/// <reference lib="dom" />
import { loginApi } from "./shared.bundle.ts";
const form = document.getElementById("loginForm") as HTMLFormElement;
const passwordInput = document.getElementById(
"passwordInput",
) as HTMLInputElement;
const errDiv = document.getElementById("errDiv") as HTMLDivElement;
form.addEventListener("submit", async (e) => {
e.preventDefault();
const password = passwordInput.value;
const res = (await loginApi.makeRequest({ password }, {})).flatten();
if (res.isErr()) {
errDiv.innerText = res.error.info;
} else {
window.location.href = "/";
}
});