Version [for Adonis v5]
This package allows you easily add role/permission based access to your AdonisJS applications routes:
- Role based route authentication
- Permission based route authentication
- Adonisjs v5
- Node >=8
- Mysql >=5
- PostgreSQL >=10
- Adonisjs5 lucid(
@adonisjs/lucid
) - Adonisjs5 auth(
@adonisjs/auth
)
You can install the package via NPM:
npm install @shagital/adonisjs-acl
Or with yarn
yarn add @shagital/adonisjs-acl
- 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
Route.get('/something-important', 'ImportantController.show').middleware('is:administrator')
Route.get('/something-important', 'ImportantController.show').middleware('is:administrator,superadmin')
Route.get('/important', 'SomeController.show').middleware('can:view-important')
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
- Add properties to models e.g
User.hasRole
,User.hasPermission
,role.hasPermission
, etc
If you have a feature you'd like to add, kindly send a Pull Request (PR)
If you discover any security related issues, please email zacchaeus@shagital.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.