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
264 stars 31 forks source link

Cannot read properties of null (reading 'includes') Error - After login in NuxtJs #47

Open m7salam opened 2 years ago

m7salam commented 2 years ago

Hello

I am using NuxtJs and keeps getting this weird error I tried moving in many places my code but it doesn't seem to work I'm using the persistent option to true

Everytime first time login I get this error image

after refreshing the page it works as it should but everytime first time logging in it gives this error

I'm using the below code in default.vue layout folder

if (this.$store.state.auth.user.companies_usernames.includes('company')) {
      this.$gates.setRoles(['superuser'])
      this.$gates.setPermissions(['all'])
    } else {
      this.$store
        .dispatch(
          'user/getCurrentUser',
          this.$store.state.auth.user.company_username
        )
        .then(() => {
          this.$gates.setRoles([this.$store.state.user.currentUser.role])
          this.$gates.setPermissions(
            this.$store.state.user.currentUser.permissions
          )
        })
    }
mreduar commented 2 years ago

Hi @m7salam Did you manage to solve your problem?

m7salam commented 2 years ago

Hi @m7salam Did you manage to solve your problem?

@mreduar I believe we have made a workaround but unfortunately not on the top of my head now, but didn't know what was causing it, sorry that I couldn't help

mreduar commented 2 years ago

I managed to solve it, the problem was that I was passing a null property. Thanks