working on user data update
This commit is contained in:
@@ -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!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user