szoe-pontok/static/js/auth.js
2024-10-11 15:58:12 +02:00

43 lines
925 B
JavaScript

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