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

30 lines
845 B
TypeScript

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