williamcruzme / vue-gates

🔒 A Vue.js & Nuxt.js plugin that allows you to use roles and permissions in your components or DOM elements, also compatible as middleware and methods.
https://williamcruzme.github.io/vue-gates/
MIT License
263 stars 31 forks source link

Nuxt: getting empty permission on first reload #57

Closed kossa closed 2 years ago

kossa commented 2 years ago

Hello,

Thank you for this great package, when I log in the the user and redirect it to my dashboard all permissions are loaded well. but if the user reload the page it does not work properly, I have :

// layouts/default.vue

async mounted() {
  const [roles, permissions] = await Promise.all([
    this.$axios.$get('/api/admin/user/roles'),
    this.$axios.$get('/api/admin/user/permissions'),
  ])

  this.$gates.setRoles(roles.data)
  this.$gates.setPermissions(permissions.data)
},
// components/layouts/menu.vue

<NuxtLink v-can="'dashboard.index'" class="sidebar-link" to="/dashboard"> Dashboard </NuxtLink> // it does not show
kossa commented 2 years ago

I fixed it by persistent: true, I thought it retrieve the permission only on login, but finally each time the page was reloaded