save username in cookie

This commit is contained in:
Florian Hoss 2022-04-04 11:40:34 +02:00
parent 539a36dffe
commit 2d98665f92
7 changed files with 149 additions and 95 deletions

View file

@ -16,12 +16,15 @@
</div>
{{template "scripts" .}}
{{template "formScripts" .}}
<script>
userLoggedIn().then((loggedIn) => loggedIn && redirect("/"));
async function submitForm(formData) {
const response = await fetch("/login", {method: 'POST', body: formData, redirect: 'follow'});
if (response.ok) {
const json = await response.json();
console.log("JSON:", json.message);
setCookie("username", json.username, 1);
redirect("/");
} else {
redirect("/login");