I've implemented a navbar that displays specific menu items based on the user's role.
Below is the simplified HTML code for the navbar:
<v-speed-dial class="speed-dial-container contextual-text-menu" v-if="user && user.emailVerified" fixed top right
direction="bottom" transition="slide-y-transition">
<v-icon v-if="checkAuthorization(['superAdmin', 'admin', 'pastor', 'member']) === true" class="mt-2"
@click="sendComponent({ component: 'Dashboard' })">$admin</v-icon>
</v-speed-dial>
Here is my method:
async checkAuthorization(permissions) {
if (permissions.length > 0) {
const temp = await this.$store.dispatch('UserData/isAuthorized', permissions)
return temp
}
},
Vuex store setup:
isAuthorized({
state
}, permissions) {
const userRoles = state.roles
if (permissions && userRoles) {
const found = userRoles.some(r => permissions.includes(r))
return found
}
},
Even though all console logs display the correct values, the menu items in the HTML do not update accordingly.
For instance, after adding 'member' to
checkAuthorization(['superAdmin', 'admin', 'pastor', 'member']) === true
, and logging in with only the 'member' role, all console logs indicate true. Despite this, the expected menu item does not appear as intended.