preparing svelte login, mastered translations
This commit is contained in:
20
frontend/src/user.svelte.js
Normal file
20
frontend/src/user.svelte.js
Normal file
@@ -0,0 +1,20 @@
|
||||
export const user = $state({
|
||||
name : null
|
||||
})
|
||||
|
||||
export async function tryLogin(credentials){
|
||||
var url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/login`;
|
||||
let response = await fetch(url,{
|
||||
headers: {
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
method: 'POST',
|
||||
body: JSON.stringify(credentials)
|
||||
});
|
||||
if (response.ok){
|
||||
const json = await response.json();
|
||||
for (var key of Object.keys(json)) user[key] = json[key];
|
||||
} else {
|
||||
alert("Login failed!");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user