var auth_form = document.getElementById("auth_form"); function login() { fetch(`${config.apiBase}/auth/login`, { method: "POST", credentials: "same-origin", body: new FormData(auth_form) }) .then(response => response.json()) .then(data => { if (data.status !== 200) { alert(data.error); console.log(data); } else { redirect("/list"); } }) .catch(error => { console.log(error); }); } function register() { fetch(`${config.apiBase}/auth/register`, { method: "POST", credentials: "same-origin", body: new FormData(auth_form) }) .then(response => response.json()) .then(data => { if (data.status !== 200) { alert(data.error); console.log(data); } else { alert("succesful registration"); } }) .catch(error => { console.log(error); }); }