adonis-imperium
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "adonis-imperium", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "This package is an **authorization provider** built on top of [imperium](https://github.com/mono-js/imperium).", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -1,4 +0,4 @@ | ||
# Adonis Imperium 🦅 | ||
# Adonis Imperium | ||
This package is an **authorization provider** built on top of [imperium](https://github.com/mono-js/imperium). | ||
This package is an **authorization provider** built on top of [imperium](https://github.com/mono-js/imperium) and inspired by [adonis-guard](https://github.com/RomainLanz/adonis-guard). | ||
@@ -40,2 +40,8 @@ ## Getting Started | ||
Imperium.role('Moderator', async () => { | ||
const posts = await Post.query().fetch() | ||
return posts.toJSON().map((post) => ({ post: post.id })) | ||
}) | ||
Imperium.role('User', async ({ auth }) => { | ||
@@ -117,3 +123,3 @@ return { user: auth.user.id } | ||
**Public API** | ||
### API | ||
@@ -120,0 +126,0 @@ ```js |
'use strict' | ||
/* global use */ | ||
const AuthorizationException = require('../Exceptions') | ||
@@ -15,3 +17,3 @@ | ||
if (await imperium.cannot(action, actionParams)) throw AuthorizationException.invoke('Unauthorized', 401, 'E_UNAUTHORIZED') | ||
if (await imperium.cannot(action, actionParams)) throw new AuthorizationException('Unauthorized', 401, 'E_UNAUTHORIZED') | ||
@@ -18,0 +20,0 @@ await next() |
'use strict' | ||
/* global use */ | ||
const Imperium = use('Imperium') | ||
@@ -4,0 +6,0 @@ |
@@ -7,3 +7,3 @@ 'use strict' | ||
async handle ({ imperium }, next, [role]) { | ||
if (await imperium.isnot(role)) throw AuthorizationException.invoke('Unauthorized', 401, 'E_UNAUTHORIZED') | ||
if (await imperium.isnot(role)) throw new AuthorizationException('Unauthorized', 401, 'E_UNAUTHORIZED') | ||
@@ -10,0 +10,0 @@ await next() |
7773
70
130