ican
v0.0.2
Published
A simple authorization library.
Downloads
3
Readme
ican
config
var ican = require('ican');
ican.get('profile', function(req, done) {
if(req.user.id === req.params.id || req.user.isAdmin) {
return done(true);
}
return done(false, 'this is not your profile');
});
ican.post('profile', function(req, done) {
if(req.user.isAdmin) {
return done(true);
}
return done(false, 'you do not have permission to create new profiles');
});
ican.put('profile', function(req, done) {
if(req.user.id === req.params.id) {
return done(true);
}
return done(false, 'this is not your profile');
});
ican.delete('profile', function(req, done) {
done(req.user.isAdmin, 'you do not have permission to delete profiles');
});
usage
var ican = require('ican');
var routes = express.Router();
routes.get('/', ican.get('profile'), function(req, res) {
});
routes.post('/', ican.post('profile'), function(req, res) {
});
app.use('/profile', routes);
additional usage
var ican = require('ican');
var routes = express.Router();
ican.use('some feature', function() {
});
routes.get('/', function() {});
app.use('/some_feature', ican.use('some feature'), routes);