easy-acl
v1.0.3
Published
To develop a easy access control list and to identify the access privilege for a specific role to a specific route.
Downloads
3
Maintainers
Readme
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'))
});
});