include axios and show toasts
This commit is contained in:
parent
712af41c28
commit
5b2252d6bd
5 changed files with 69 additions and 19 deletions
|
@ -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>
|
||||
|
|
Reference in a new issue