feat/menu-structure: update access control

This commit is contained in:
Andrian Roshandy
2025-11-12 06:51:37 +07:00
parent 02c14089f1
commit f0d2bc4de1
2 changed files with 72 additions and 53 deletions
+24 -5
View File
@@ -5,12 +5,13 @@ export const useUserStore = defineStore(
// const token = useCookie('authentication')
const isAuthenticated = computed(() => !!user.value)
const userRole = computed(() => {
const roles = user.value?.roles || []
return roles.map((input: string) => {
const parts = input.split('-')
return parts.length > 1 ? parts[1]: parts[0]
})
return user.value?.roles || []
// return roles.map((input: string) => {
// const parts = input.split('|')
// return parts.length > 1 ? parts[1]: parts[0]
// })
})
const login = async (userData: any) => {
@@ -21,12 +22,30 @@ export const useUserStore = defineStore(
user.value = null
}
const setActiveRole = (role: string) => {
if (user.value && user.value.roles.includes(role)) {
user.value.activeRole = role
}
}
const getActiveRole = () => {
if (user.value?.activeRole) {
return user.value.activeRole
}
if (user.value?.roles.length > 0) {
user.value.activeRole = user.value.roles[0]
return user.value.activeRole
}
}
return {
user,
isAuthenticated,
userRole,
login,
logout,
setActiveRole,
getActiveRole,
}
},
{