@shagital/adonisjs-acl
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

AdonisJS ACL

npm npm (scoped) NPM

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

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 to Server.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 zacchaeus@shagital.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Package Sidebar

Install

npm i @shagital/adonisjs-acl

Weekly Downloads

20

Version

1.0.1

License

MIT

Unpacked Size

25.8 kB

Total Files

26

Last publish

Collaborators

  • djunehor