easy-acl

1.0.3 • Public • Published

easy-acl

Easy Access control list development and to give access to specific route for a specific role.

Installation

$ npm install easy-acl

Usage

(index.js)

var acl = require('easy-acl');
var config = require('../config');

/* Middleware before every route */
app.use(function (req, res, next) {
	// school_admin is a userType collected from session or by any other means. 
    acl.hasAccess('school_admin', req.path, config.roles, function (isTrue) {
        if (isTrue)
            return next();
        else
            return next(new Error('You do not have access permission'))
    });

})

(config.js)

module.exports = {
  roles: {
    school_admin: ['/school'],
    student: ['/student'],
    teacher: ['/teacher','resources/teacher']
  }
};

OR

var acl = require('easy-acl');

/* Middleware before every route */
app.use(function (req, res, next) {
 var roles = {
    school_admin: ['/school'],
    student: ['/student'],
    teacher: ['/teacher','resources/teacher']
  };
  acl.roles= roles;
	// school_admin is a userType collected from session or by any other means. 
  acl.hasAccess('school_admin', '/school', function (isTrue) {
        if (isTrue)
            return next();
        else
            return next(new Error('You do not have access permission'))
    });
});

Package Sidebar

Install

npm i easy-acl

Weekly Downloads

3

Version

1.0.3

License

ISC

Last publish

Collaborators

  • masureshho