From c2577184107d47cd714210b10d35ec1bd10c0ce3 Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Sat, 14 Oct 2023 22:34:41 -0600 Subject: [PATCH] feat: added login flow to frontend --- frontend/login.mts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/frontend/login.mts b/frontend/login.mts index 1c1ffb6..19c1497 100644 --- a/frontend/login.mts +++ b/frontend/login.mts @@ -24,6 +24,24 @@ document.addEventListener('DOMContentLoaded', () => { return errReset('Password is required!', Elements.submitButton); alert(`Attempting to login user [${Elements.usernameInput.value}]`); - Elements.submitButton.disabled = false; + + fetch('/api/login', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + username: Elements.usernameInput.value, + password: Elements.passwordInput.value + }) + }) + .then((res) => res.json()) + .then((data: { + success: boolean, + message: string + }) => { + if (!data.success) alert(data.message); + else window.location.href = '/user'; + }) + .catch((err) => errAlert('POST to /api/login failed!', err)) + .finally(() => Elements.submitButton.disabled = false); }); });