Giter Site home page Giter Site logo

vue-guard's Introduction

Vue-Guard

Authorization utilities for Vue 2 JS Apps.

Installation

$ yarn add @waju/vue-guard

Setup

import Permissions from "@waju/vue-gaurd"

Vue.use(Permissions, { router, errorRoute: "/403" });
new Vue({
 router,
 //Provide a data or function member of your root component named `permissions` which returns the user's permissions.
 permissions() {
   return this.$store.getters.userPermissions;
 },
 render: h => h(App),
...// other options
}).$mount('#app')

API

To guard a component tree, or say button

//permissions here are the required permissions
<v-guard :permissions="['is-admin', 'can-view-posts']">
 <SomeComponent />
</v-guard>

To guard Vue-Router routes

const routes = [
 {
  path: ':id/edit',
  name: 'EditPost',
  meta: { 
    guard: {
      permissions: ['edit-posts', 'manage-posts'],
      all: true
    },
 }
]

For imperative logic two methods are injected into every component

  • $permitsAny takes an array of permissions and returns true if the user has any of those permissions
  • $permitsAll takes an array of permissions and returns true if the user has all of those permissions.

Contributing

Please use this library and open issues if you find any bugs, also feel free to submit PR's with fixes, improvements and new features.

vue-guard's People

Contributors

wajuabolarin avatar

Stargazers

Tony Michael avatar  avatar Roman avatar Emilie Marchand avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.