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); }); });