async function checkLogin() { let resp = await fetch('../whoami') if (resp.ok) { console.log("Already logged in, let's change password instead") document.location.href = 'change.html' } data = await resp.json() } async function onSubmit(evt) { evt.preventDefault() let resp = await fetch('../login', { method: 'POST', body: JSON.stringify({ username: document.querySelector('#login-form input[name=username]').value, password: document.querySelector('#login-form input[name=password]').value, }) }) console.log('ok', resp) document.location.href = '../' } function initLogin() { checkLogin() document.getElementById("login-form").addEventListener('submit', onSubmit, false) } document.addEventListener('DOMContentLoaded', initLogin)