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.

Home Page:https://williamcruzme.github.io/vue-gates/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

m7salam opened this issue · comments

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
          )
        })
    }

Hi @m7salam Did you manage to solve your problem?

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

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