
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
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
The npm package koa-jwt-roles receives a total of 0 weekly downloads. As such, koa-jwt-roles popularity was classified as not popular.
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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.