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

Using persistent causes an error #30

Closed strotgen closed 3 years ago

strotgen commented 3 years ago

Hi John, thanks for developing this package.

I upgraded recently and started getting the following error: #

Uncaught SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at new Gate (vue-gates.js?e1b1:221)
    at Object.install (vue-gates.js?e1b1:323)
    at Function.Vue.use (vue.runtime.esm.js?2b0e:5107)
    at eval (vue-gates.js?511d:4)
    at Module../plugins/vue-gates.js (app.js:951)

Checking the source code, I saw that the constructor is trying to parse localStorage.getItem('roles') but this returns undefined, hence the error.

I'm using Nuxt, latest version. And I set the roles and permissions inside a Nuxt Auth plugin.

Is this an expected behaviour or am I doing something wrong? If not, I can PR a quick fix for this.