npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pintahub/admin-middleware

v1.1.1

Published

Express middleware for admin services: JWT authentication and role-based authorization.

Readme

@pintahub/admin-middleware

Express middleware for admin services: JWT authentication and role-based authorization.

Setup

const {Middleware} = require('@pintahub/admin-middleware')

const middleware = new Middleware({secretKey: process.env.JWT_SECRET_KEY})

module.exports = middleware

Token.authenticated()

Verifies the Authorization: Bearer <jwt> header and puts the decoded payload on the request:

| Property | Value | |--------------------------|----------------------------------| | req.authenticatedAccount | the full decoded JWT payload | | req.accountId | _id claim | | req.accountRole | role claim |

A missing, expired, or invalid token responds 403 {success: false, message}.

Token.requireRole(...roles)

Allows the request through only when req.accountRole is one of roles. Anything else — wrong role, or no role on the request at all — responds 403 {success: false, message}.

const {Token} = require('../connections/middleware')

router.get('/accounts', Token.authenticated(), Token.requireRole('admin'), ctrl.listAccounts)
router.get('/orders', Token.authenticated(), Token.requireRole('admin', 'seller'), ctrl.listOrders)

It must be mounted after authenticated() — that is what sets req.accountRole. Mounting it alone denies every request (fails closed) rather than letting them through, so a route that forgets authenticated() returns 403 instead of leaking. Role matching is exact and case-sensitive (Account.role values are stored lowercase: 'admin', 'seller').

Calling it with no roles — requireRole(), or requireRole(['admin']) instead of requireRole('admin') — would allow nobody, so it throws at route-registration time (app boot) rather than silently 403-ing every request in production.

Authorization trusts the JWT claim

The role is read from the token, not from the database, so there is no lookup on the request path. The trade-off: a token stays valid for its full lifetime (30d with remember me, otherwise 7d), so an account whose role is downgraded keeps its old privileges until the token expires. That is accepted for an internal tool. To revoke immediately, the role would have to be looked up per request via options.getModel (declared in src/interfaces/Options.ts, currently unused).

Development

yarn build   # tsc -> dist/
yarn test    # build, then run the verification scripts in test/

Only dist/ is published (see .npmignore); prepublishOnly rebuilds it so a manual npm publish always ships a fresh build.