Merge branch 'master' of git.reim.ar:ReiMerc/temperature-alarm

This commit is contained in:
Jeas0001 2025-03-31 11:16:29 +02:00
commit 1ca64702d7
2 changed files with 8 additions and 5 deletions

View File

@ -10,7 +10,7 @@ document.getElementById("loginForm").addEventListener("submit", function(event)
login(emailOrUsername, password)
.then(response => {
document.cookie = `auth-token=${response.token}`;
document.cookie = `auth-token=${response.token}; Path=/`;
localStorage.setItem("user", {
id: response.id,

View File

@ -3,13 +3,16 @@ import { address } from "./constants.js";
export async function request(method, path, body = null) {
const token = document.cookie.match(/\bauth-token=([^;\s]+)/);
const headers = {};
if (body)
headers["Content-Type"] = "application/json";
if (token?.length > 1)
headers["Authorization"] = `Bearer ${token[1]}`;
return new Promise((resolve, reject) => {
fetch(address + path, {
method,
headers: {
"Content-Type": body ? "application/json" : undefined,
"Authorization": token?.length > 1 ? `Bearer ${token[1]}` : undefined,
},
headers,
body: body ? JSON.stringify(body) : undefined,
})
.then(async response => {