/cancan

Pleasant authorization library for Node.js

Primary LanguageJavaScriptMIT LicenseMIT

CanCan

Build Status Coverage Status

CanCan provides a simple API for handling authorization of actions. Permissions are defined for each class using a simple can function.





Installation

$ npm install cancan --save

User Guide

Read the interactive user guide on Bucket

Quick Look

const cancan = require('cancan');
const can = cancan.can;


// example classes
class AdminUser {}
class User {}

class Product {}


// define permissions
cancan.configure(User, function (user) {
  // this user can view
  // all instances of Product
  this.can('view', Product);
});

cancan.configure(AdminUser, function (user) {
  // this user can:
  //  1. view all products
  //  2. create a new product
  this.can('view', Product);
  this.can('create', Product);
});


// check access
let product = new Product();

let adminUser = new AdminUser();
let user = new User();

can(adminUser, 'view', product); // true
can(adminUser, 'create', product); // true

can(user, 'view', product); // true
can(user, 'create', product); // false

Tests

$ npm test

License

MIT © Vadym Demedes