Implemented actual authentication guards, began implementing main login user flows
This commit is contained in:
@@ -3,8 +3,25 @@ import { defineStore } from 'pinia'
|
||||
|
||||
export const useUserStore = defineStore('user', () => {
|
||||
const user = ref(null)
|
||||
const roles = ref<string[]>([])
|
||||
const roles = computed(() => { user.value.roles })
|
||||
const loaded = ref(false);
|
||||
|
||||
const isLoggedIn = computed(() => user.value !== null)
|
||||
return { user, isLoggedIn, roles }
|
||||
|
||||
async function loadUser() {
|
||||
//@ts-ignore
|
||||
const res = await fetch(`${import.meta.env.VITE_APIHOST}/members/me`, {
|
||||
credentials: 'include',
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
console.log(data);
|
||||
user.value = data;
|
||||
}
|
||||
|
||||
loaded.value = true;
|
||||
}
|
||||
|
||||
return { user, isLoggedIn, roles, loadUser, loaded }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user