All Projects → leonardovilarinho → vue-acl

leonardovilarinho / vue-acl

Licence: other
Access Control List plugin for VueJS 2.0

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects
HTML
75241 projects

Projects that are alternatives of or similar to vue-acl

Vue Browser Acl
Easy user access control in Vue for better UX. Build on top of the browser-acl package.
Stars: ✭ 162 (-57.48%)
Mutual labels:  acl, vue-router
Vue Acl
Access Control List plugin for VueJS 2.0
Stars: ✭ 376 (-1.31%)
Mutual labels:  acl, vue-router
electron-vue-boilerplate
Simple boilerplate for building Vue app with Electron and Webpack.
Stars: ✭ 53 (-86.09%)
Mutual labels:  vue-router
guide vue-cli-3-multiple-entry-points
Simple guide to show how to create multiple entry points (pages) using vue-cli-3
Stars: ✭ 29 (-92.39%)
Mutual labels:  vue-router
vue-iview-admin-template
Vue 2.0 admin template based on View UI
Stars: ✭ 43 (-88.71%)
Mutual labels:  vue-router
vue-tsx-admin
基于typscript+jsx+vue+ant-design-vue+ant-design-pro的中后台模板
Stars: ✭ 53 (-86.09%)
Mutual labels:  vue-router
paper-survey
Summary of machine learning papers
Stars: ✭ 26 (-93.18%)
Mutual labels:  acl
casbin-ex
An authorization library that supports access control models like ACL, RBAC, ABAC in Elixir
Stars: ✭ 37 (-90.29%)
Mutual labels:  acl
Vue-Notes-App
A Notes-App created with Vue. Basically it's a MEVN app!!
Stars: ✭ 28 (-92.65%)
Mutual labels:  vue-router
vite-vue-admin
🎉🎉使用Vite + Vue3 + TypeScript + Element-plus + Mock开发的后台管理系统🎉🎉
Stars: ✭ 97 (-74.54%)
Mutual labels:  vue-router
vue3-webpack-boilerplate
Vue 3 Webpack Boilerplate (Vue 3, Vue Router 4, Vuex 4, Typescript)
Stars: ✭ 69 (-81.89%)
Mutual labels:  vue-router
aura-admin
Aura Admin is the Web App that helps you to mange the Tech Communities like GDGs, DSCs or any other tech communities with Aura
Stars: ✭ 58 (-84.78%)
Mutual labels:  vue-router
speedle-plus
Speedle+ is an open source project for access management. It is based on Speedle open source project and maintained by previous Speedle maintainers.
Stars: ✭ 45 (-88.19%)
Mutual labels:  acl
capacitor-vue-ionicv4-app
sample app using capacitor vuejs and ionicv4 components
Stars: ✭ 70 (-81.63%)
Mutual labels:  vue-router
lumen-vue-todo
ToDo App with Lumen, Vue.js, Vue Router and Vuex
Stars: ✭ 33 (-91.34%)
Mutual labels:  vue-router
Build-vue-hackernews-2.0-from-scratch
A tutorial for beginners to build a complex project with Vue.js 2.0 step by step
Stars: ✭ 85 (-77.69%)
Mutual labels:  vue-router
special-vue-series-code-analyzing
「Vue生态库源码系列」,Vue、Vue-router、Vuex、Vue-cli、Vue-loader、Vue-devtools等
Stars: ✭ 15 (-96.06%)
Mutual labels:  vue-router
vue-vben-admin
A modern vue admin. It is based on Vue3, vite and TypeScript. It's fast!
Stars: ✭ 12,169 (+3093.96%)
Mutual labels:  vue-router
vue-bootstrap-boilerplate
📦 Vue 2/3, Bootstrap 5, Vuex, Vue-Router, Sass/Scss, ESLint, Axios (switch to vue3 branch)
Stars: ✭ 86 (-77.43%)
Mutual labels:  vue-router
nestjs-toolbox
The repository contains a suite of components and modules for Nest.js
Stars: ✭ 166 (-56.43%)
Mutual labels:  acl

vue-acl: access control list in vuejs

We will help you to control the permission of access in your app for yours components and routes

Installation

# yarn
yarn add vue-acl
# npm
npm install vue-acl --save

Get Started

Create the acl.js file to define your acl settings and global rules:

import Vue from 'vue'
import { AclInstaller, AclCreate, AclRule } from 'vue-acl'
import router from './router'

Vue.use(AclInstaller)

export default new AclCreate({
  initial: 'public',
  notfound: {
    path: '/error',
    forwardQueryParams: true,
  },
  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')
  }
})

More details:

  • AclInstaller: plugin class for install in Vue with Vue.use
  • AclCreate: class to define acl settings
    • initial: first permission, for startup with your app
    • notfound: route for 404 error, add forwardQueryParams: true if you want to forward all query params,
    • router: your VueRouter instance
    • acceptLocalRules: if you can define new rules inside vue components
    • globalRules: define globals rules for access in routes and any components
    • middleware: async method executed in all route change event, to get user in your api and change permission
  • AclRule: class with rule builder, the instance receive initial permission.
    • or: method for add OR condition in rule, e.g: if current permission is public OR admin the rule isPublic equals true
    • and: method for add AND condition in rule, e.g: if current permission contains user AND inside the rule isLogged equals true
    • generate: this method should called to create and compile your rule query

In your router.js file, you can define permissions for yours routes:

import Vue from 'vue'
import Router from 'vue-router'
import { AclRule } from 'vue-acl'

import Public from './views/Public.vue'
import Admin from './views/Admin.vue'
import NotFound from './views/NotFound.vue'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'public',
      component: Public,
      meta: {
        rule: 'isPublic'
      }
    },
    {
      path: '/admin',
      name: 'admin',
      component: Admin,
      meta: {
        rule: new AclRule('admin').generate()
      }
    },
    {
      path: '/error',
      name: 'notfound',
      component: NotFound,
      meta: {
        rule: '*'
      }
    }
  ]
})

More details:

  • Define rule meta for link a route with a permission, your can use name of the global rule e.g isPublic or use AclRule for create new rule orr use * for define allowed route.

For finish, in your main.js import the acl and pass to Vue root instance:

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import acl from './acl'

Vue.config.productionTip = false

new Vue({
  router,
  acl,
  render: h => h(App)
}).$mount('#app')

Use in components

If you defined acceptLocalRules as true, you can define computed properties with new rules, but this rules works only in component:

import { AclRule } from 'vue-acl'

export default {
  computed: {
    isLocalRule () {
      return new AclRule('create').generate()
    }
  }
}

You can also check rules for display custom elements in your layout:

<button v-if="$acl.not.check('isAdmin')">
  Set admin permisson
</button>
<button v-else>
  Set public permission
</button>

E.g: if isAdmin is not true the button 'Set admin permisson' is displayed.

Finish, you can change current permission in any component using change method:

<button v-if="$acl.not.check('isAdmin')" @click="$acl.change('admin')">
  Set admin permisson
</button>
<button v-else @click="$acl.change('public')">
  Set public permission
</button>

You can also add a new permission during execution, taking the current one and concatenating it with the new one: this.$acl.change(this.$acl.get.concat(['read', 'write']))

In your component can add observer for current Rule:

mounted () {
  this.$acl.onChange = newPermission => {
    console.log('Has changed to', newPermission)
  }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].