Set auth token when logging in

This commit is contained in:
Reimar 2025-03-27 09:08:34 +01:00
parent 0f1b10d2d7
commit 02bfbabcfc
Signed by: Reimar
GPG Key ID: 93549FA07F0AE268
2 changed files with 8 additions and 2 deletions

View File

@ -10,10 +10,16 @@ document.getElementById("loginForm").addEventListener("submit", function(event)
login(emailOrUsername, password)
.then(response => {
document.cookie = `auth-token=${response.token}`;
localStorage.setItem("user", {
id: response.id,
username: response.userName,
});
location.href = "/home";
})
.catch(error => {
console.log(error);
document.getElementById("form-error").innerText = error;
document.getElementById("form-error").style.display = "block";
});

View File

@ -1,7 +1,7 @@
import { address } from "./constants.js";
export async function request(method, path, body = null) {
const token = document.cookie.match(/\bauth-token=(\S+)/);
const token = document.cookie.match(/\bauth-token=([^;\s]+)/);
return new Promise((resolve, reject) => {
fetch(address + path, {