include axios and show toasts

This commit is contained in:
Florian Hoss 2022-04-05 21:21:48 +02:00
parent 712af41c28
commit 5b2252d6bd
5 changed files with 69 additions and 19 deletions

View file

@ -6,6 +6,7 @@
{{template "head" .}}
</head>
<body>
{{template "toasts" .}}
{{template "navbar" .}}
<div class="position-absolute top-50 start-50 translate-middle">
@ -20,15 +21,15 @@
<script>
userLoggedIn().then((loggedIn) => loggedIn && redirect("/"));
async function submitForm(formData) {
const response = await fetch("/auth/login", {method: 'POST', body: formData, redirect: 'follow'});
if (response.ok) {
const json = await response.json();
setCookie("username", json.username, 1);
redirect("/");
} else {
redirect("/view/login");
}
function submitForm(formData) {
axios({method: 'POST', url: '/auth/login', data: formData})
.then((response) => {
setCookie("username", response.data.username, 1);
redirect("/");
})
.catch((response) => {
showErrorToast(response.message);
});
}
</script>
</body>