router now working, implemented login and logout
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -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'
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user