koa2-rbac
Simple rbac for koa better use with koa-router
Installation
$ npm install koa2-rbac
API
new Role(options)
Param | Type | Description |
---|---|---|
[options] | Object |
Options |
[options.getRole] | (ctx, next) => string |
return current role |
[options.denyHandler] | (ctx, next) => void |
default deny handler |
Example
Basic usage with koa-router
, use named routes(not required) to enable easy error message:
const Koa = ;const Router = ;const Role = ; const app = ;const router = ;const role = { return ctx_userrole; } { const _matchedRouteName: matchedRouteName = ctx; ctxstatus = 403; ctxbody = error: matchedRouteName ? `Access Denied - You don't have permission to :: ` : "Access Denied - You don't have permission" ; };
roles.is(roles, denyHanlder) => Koa.Middleware | void
Param | Type | Description |
---|---|---|
[role] | string | string[] |
Allowed roles |
[denyHandler] | (ctx, next) => string |
deny handler for current route |
Example
Basic usage with koa-router
router; router; router; router;
License
MIT