adonis-imperium
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "adonis-imperium", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "This package is an **authorization provider** built on top of [imperium](https://github.com/mono-js/imperium).", | ||
@@ -19,3 +19,8 @@ "repository": { | ||
"standard": "12.0.1" | ||
}, | ||
"standard": { | ||
"globals": [ | ||
"use" | ||
] | ||
} | ||
} |
@@ -115,9 +115,44 @@ # Adonis Imperium | ||
```js | ||
Route.get('/admin/posts', 'Admin/PostController.index') | ||
Route.get('/posts', 'PostController.index') | ||
.middleware(['auth', 'is:Admin']) | ||
Route.get('/admin/posts', 'Admin/PostController.show') | ||
.middleware(['auth', 'can:showPost']) | ||
Route.put('/posts/:id', 'PostController.update') | ||
.middleware(['auth', 'can:updatePost']) | ||
``` | ||
You can also use AdonisJs resources: | ||
```js | ||
Route.resource('posts', 'PostController') | ||
.only(['index', 'show', 'store', 'update', 'destroy']) // .apiOnly() | ||
.middleware(new Map([ | ||
[['store', 'update', 'destroy'], ['auth']], | ||
[['store'], ['can:storePost']], | ||
[['update'], ['can:updatePost']], | ||
[['destroy'], ['can:destroyPost']] | ||
])) | ||
.validator(new Map([ | ||
[['store'], ['StorePost']], | ||
[['update'], ['UpdatePost']] | ||
])) | ||
``` | ||
### Config | ||
In order to configure how the `can` middleware will process the route context (like in validators or controllers) you can define functions in `config/acl.js`: | ||
```js | ||
module.exports = { | ||
updatePost: ({ params }) => ({ post: params.id }), | ||
destroyPost: ({ params }) => ({ post: params.id }), | ||
storePost: ({ params, request }) => { | ||
const { type } = request.post() | ||
return { | ||
type | ||
} | ||
} | ||
} | ||
``` | ||
### API | ||
@@ -124,0 +159,0 @@ |
'use strict' | ||
/* global use */ | ||
const AuthorizationException = require('../Exceptions') | ||
@@ -6,0 +4,0 @@ |
'use strict' | ||
/* global use */ | ||
const Imperium = use('Imperium') | ||
@@ -6,0 +4,0 @@ |
8646
165
68