leonardovilarinho / vue-acl

Access Control List plugin for VueJS 2.0
375 stars 76 forks source link

Call $acl object in vue-router beforeEach for vue-acl version 4.0.7 #65

Closed akmalhazim closed 5 years ago

akmalhazim commented 5 years ago

Hi,

I need to find a way to call the $acl object in vue-router beforeEach so that I can call $acl.change in the beforeEach middleware. I'm using vue-acl 4.0.7. Please help.

Thanks !!

Kind Regards, Akmal Hazim.

leonardovilarinho commented 5 years ago

Hi, in the latest version I added the middleware property in the plugin installation. Use it to do this.

export default new AclCreate({
  initial: 'public',
  notfound: '/error',
  router,
  acceptLocalRules: true,
  globalRules: {
    isAdmin: new AclRule('admin').generate(),
    isPublic: new AclRule('public').or('admin').generate(),
    isLogged: new AclRule('user').and('inside').generate()
  },
  middleware: async acl => {
    await timeout(2000) // call your api
    acl.change('admin')
  }
})