0.1.4 • Published 3 years ago
aclatraz v0.1.4
Aclatraz
Simple dependency-free package for ACL. It can handle hundreds of roles easily.
Install
npm install aclatraz
How it works
- Create the rules (they can be roles as well)
- Load them into Aclatraz
- Generate permission tokens based on rules
- Verify token
TypeScript example
import { Aclatraz } from 'aclatraz';
// Create an ACL instance. Don't forget to store
// somewhere the rules (preferably in DB, or in a file)
const acl = new Aclatraz([
{
id: 1,
slug: 'READ_USER',
},
]);
// Add new rule on the fly
acl.addRule({
id: 2,
slug: 'CREATE_USER',
name: 'Protect registration with this rule',
});
// User with this token can access id: 1 rule
const permissionToken = acl.generateAclCode([1]);
console.log(acl.verify(permissionToken, 1)); // true
console.log(acl.verify(permissionToken, 2)); // false
How to use as an express middleware
Soon...
How to use as a fastify middleware
Soon...
How to use as a NestJS guard
Soon...