blob: 42b324240aec8405a95398d416a0be5d6201c8aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
function display_error(message) {
document.getElementById("error-message").innerHTML = `Error: ${message}`;
document.getElementById("error").hidden = false;
}
function init() {
const form = document.getElementById("login-form");
form.addEventListener("submit", async (e) => {
e.preventDefault();
const body = {}
new FormData(form).forEach((value, key) => body[key] = value);
try {
console.log();
const res = await fetch("/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
credentials: "include",
body: JSON.stringify(body)
});
if (!res.ok) {
const error = await res.json();
display_error(error.error);
return;
}
window.location.href = "index.html";
} catch (err) {
console.log(err);
//display_error("network error");
}
});
}
|