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

1.0.4 • 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 @steveyout/adonis5-acl

Or with yarn

yarn add @steveyout/adonis5-acl

Setup

  • Configure package with node ace configure @steveyout/adonis5-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 @steveyout/adonis5-acl

Weekly Downloads

8

Version

1.0.4

License

MIT

Unpacked Size

26.7 kB

Total Files

18

Last publish

Collaborators

  • steveyout