Implement authentication in frontend

This commit is contained in:
2025-10-04 15:54:31 +02:00
parent 884d674765
commit dd0fb6f5ba
3 changed files with 48 additions and 21 deletions

View File

@@ -23,20 +23,19 @@
return extractFromErrorFromField("Password", errors.value);
})
function onSubmit(e) {
postLogin(user)
.then((res) => {
if (res.ok) {
res.json().then((json) => login(user.value.username, json));
router.push('/');
return;
} else {
res.json().then((json) => (errors.value = json));
}
})
async function onSubmit(e) {
const res = await postLogin(user)
if (res.ok) {
let json = await res.json();
await login(user.value.username, json);
router.push('/');
return;
} else {
res.json().then((json) => (errors.value = json));
}
}
function login(username, json) {
async function login(username, json) {
useAuthStore().login({username: username, token: json["token"]})
}
</script>