Package Exports
- browser-acl
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (browser-acl) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
browser-acl
Simple ACL library for the browser inspired by Laravel's guards and policies.
Install
yarn add browser-aclUsage
import Acl from 'browser-acl'
const acl = new Acl()
// Attach acl function to user class/constructor
// Adds: user.can() function
acl.attach(User)
acl.rule('view', Post)
acl.rule(['edit', 'delete'], Post, (user, post) => post.id === user.id)
if (user.can('edit', post)) {
// code for when user has permission
}Policies are also supported:
acl.policy({
view: () => true,
edit: (user, post) => post.id === user.id),
}, Post)
if (user.can('edit', post)) {
// code for when user has permission
}Note: policies takes precedence over rules.