working on user data update

This commit is contained in:
2025-07-01 08:53:07 +02:00
parent 7ef36fedff
commit 2dc45456f9
6 changed files with 42 additions and 17 deletions

View File

@@ -3,18 +3,18 @@ export const user = $state({
})
export async function checkUser(){
var url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/whoami`;
let response = await fetch(url,{
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/whoami`;
const response = await fetch(url,{
credentials: 'include'
});
if (response.ok){
const json = await response.json();
for (var key of Object.keys(json)) user[key] = json[key];
for (let key of Object.keys(json)) user[key] = json[key];
}
}
export async function logout(){
var url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/logout`;
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/logout`;
await fetch(url,{
credentials: 'include'
});
@@ -22,7 +22,7 @@ export async function logout(){
}
export async function tryLogin(credentials){
var url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/login`;
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/login`;
let response = await fetch(url,{
credentials: 'include',
headers: {
@@ -33,7 +33,7 @@ export async function tryLogin(credentials){
});
if (response.ok){
const json = await response.json();
for (var key of Object.keys(json)) user[key] = json[key];
for (let key of Object.keys(json)) user[key] = json[key];
} else {
alert("Login failed!");
}