@shagital/adonisjs-acl
v1.0.1
Published
Role & Permission support for Adonisjs
Downloads
65
Maintainers
Readme
AdonisJS ACL
Version [for Adonis v5]
This package allows you easily add role/permission based access to your AdonisJS applications routes:
Available Features
- Role based route authentication
- Permission based route authentication
Requirements
- Adonisjs v5
- Node >=8
- Mysql >=5
- PostgreSQL >=10
Dependencies
- Adonisjs5 lucid(
@adonisjs/lucid
) - Adonisjs5 auth(
@adonisjs/auth
)
Installation
You can install the package via NPM:
npm install @shagital/adonisjs-acl
Or with yarn
yarn add @shagital/adonisjs-acl
Setup
- Configure package with
node ace configure @shagital/adonisjs-acl
- In
start/kernel.ts
, add the following toServer.middleware.registerNamed
:
is: () => import('App/Middleware/Is'),
can: () => import('App/Middleware/Can'),
- Update
config/rolePermission.ts
to customize table names - Run migration to create role and permission tables:
node ace migration:run
Usage
Role Based Access
Route.get('/something-important', 'ImportantController.show').middleware('is:administrator')
Multiple Roles
Route.get('/something-important', 'ImportantController.show').middleware('is:administrator,superadmin')
Permission Based Access
Route.get('/important', 'SomeController.show').middleware('can:view-important')
Multiple Roles
Route.get('/important', 'SomeController.show').middleware('can:view-important,read-important')
NB: User is granted access if they have one or more role/permission specified
Todo
- Add properties to models e.g
User.hasRole
,User.hasPermission
,role.hasPermission
, etc
Contributing
If you have a feature you'd like to add, kindly send a Pull Request (PR)
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.