Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
koa-jwt-roles
Advanced tools
Koa role middleware for use with koa-jwt.
Written for Koa 2 with Node 7.6+
For the Koa 1 version, use the latest 0.x version.
npm i -S koa-jwt-roles
This module checks against the context user decoded by koa-jwt.
//... app, koa-jwt, koa-router
const roles = require('koa-jwt-roles');
// single check
router.get('/', roles('admin'), async function (ctx) {
// if the jwt has admin in roles, this will hit
});
// multiple check
router.get('/', roles(['admin', 'moderator']), async function (ctx) {
// if the jwt has admin or moderator, this will hit
});
If you have a lot of routes, the previous example can become very tedious. The next example makes life a bit easier if an entire route prefix uses the same roles.
// this could be an admin router where you only want admin to access.
... app, koa-jwt, koa-router
const roles = require('koa-jwt-roles');
router.use(roles('admin'));
router.get('/user/:id', async function (ctx) {
// admin can access this
});
FAQs
Koa role middleware for use with koa-jwt
We found that koa-jwt-roles demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.