auth-perm
v0.0.3
Published
A simple level-based permission / authorization / access control
Downloads
4
Maintainers
Readme
auth-perm
A simple level-based permission authorization
Install
npm install --save auth-perm
Usage
const perm = new Permissions({
admins: ['adminId1', 'adminId2'], // Admin user ids
defaultLevel: 0, // Default required user permission level
authenticatedLevel = 1, // Level assigned to authenticated users
adminLevel = 10, // Level assigned to admin user
});
// Returns true if allowed.
perm.check(
{
p: 2, // User permission level required for this check
a: ['allowedUserId1'], // Whitelisted user ids
b: ['blockedUserId1'], // Blacklisted user ids
},
'sessionUserId', // Optional user id.
// If provided, authenticated user level will be assigned.
// Also, it will be tested against whitelist and blacklist ids.
// If not provided, user permission level will be 0.
3 // Optional user level.
// If provided, this value will be used as the user's permission level.
);