diff options
| author | Daniel Hader <[email protected]> | 2026-05-29 18:14:31 -0500 |
|---|---|---|
| committer | Daniel Hader <[email protected]> | 2026-05-29 18:14:31 -0500 |
| commit | 772c7844c4ca1de632f64eb9428e8e97eea64ac1 (patch) | |
| tree | 2b038268f0d15a02830f4c4e465a323f43ce3c35 /static/login.js | |
| parent | 334867ba0732f85a48ad88ef8f3201c10bc1da4e (diff) | |
login page interaction with server
Diffstat (limited to 'static/login.js')
| -rw-r--r-- | static/login.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/static/login.js b/static/login.js new file mode 100644 index 0000000..ee135f8 --- /dev/null +++ b/static/login.js @@ -0,0 +1,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; + } + + //const result = await res.json(); + + } catch (err) { + console.log(err); + //display_error("network error"); + } + }); +} |
