router now working, implemented login and logout

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-06-30 23:40:26 +02:00
parent 56cdedcdb8
commit 956281e749
7 changed files with 113 additions and 24 deletions

View File

@@ -2,9 +2,29 @@ export const user = $state({
name : null
})
export async function checkUser(){
var url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/whoami`;
let 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];
}
}
export async function logout(){
var url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/logout`;
await fetch(url,{
credentials: 'include'
});
user.name = null;
}
export async function tryLogin(credentials){
var url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/login`;
let response = await fetch(url,{
credentials: 'include',
headers: {
'Content-Type':'application/json'
},