Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-jwt-roles

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-jwt-roles

Koa role middleware for use with koa-jwt

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

koa-jwt-roles

Koa role middleware for use with koa-jwt.

npm version

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.

Simple usage:

//... 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
});

Router usage:

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
});

Keywords

FAQs

Package last updated on 21 Aug 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc