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

jwt-auth-handler

v1.0.5

Published

A lightweight, modular authentication toolkit for Node.js applications.

Readme

📦 jwt-auth-handler

A lightweight, modular authentication toolkit for Node.js applications.

It provides JWT utilities, authentication middleware, role-based access control, and password helpers designed for real-world backend APIs.


⚡ Features

  • 🔐 JWT token generation & verification
  • 🛡️ Authentication middleware for Express-style apps
  • 🎭 Role-based access control (RBAC)
  • 🔑 Password hashing & comparison (bcrypt-based)
  • ⚙️ Lightweight, zero framework lock-in
  • 🚀 Easy integration in minutes

📥 Installation

npm install jwt-auth-kit

🚀 Quick Start

1. Create a token

const jwtAuth = require("jwt-auth-kit");

const token = jwtAuth.generateToken(
  { id: 1, role: "admin" },
  "SECRET_KEY",
  { expiresIn: "1h" }
);

console.log(token);

2. Verify a token

const decoded = jwtAuth.verifyToken(token, "SECRET_KEY");

console.log(decoded);

3. Protect routes (Authentication Middleware)

const express = require("express");
const jwtAuth = require("jwt-auth-kit");

const app = express();

const auth = jwtAuth.authMiddleware("SECRET_KEY");

app.get("/profile", auth, (req, res) => {
  res.json({
    message: "Protected route accessed",
    user: req.user,
  });
});

4. Role-based access control

const adminOnly = jwtAuth.roleMiddleware(["admin"]);

app.delete("/users", auth, adminOnly, (req, res) => {
  res.json({ message: "User deleted successfully" });
});

5. Password utilities

const { hashPassword, comparePassword } = require("jwt-auth-kit");

async function run() {
  const hash = await hashPassword("myPassword123");

  const isValid = await comparePassword("myPassword123", hash);

  console.log({ hash, isValid });
}

run();

🧱 API Reference

🔐 generateToken(payload, secret, options)

Creates a JWT token.

generateToken({ id, role }, secret, { expiresIn: "1h" });

🔍 verifyToken(token, secret)

Verifies and decodes a token.

Returns decoded payload or null.


🛡 authMiddleware(secret)

Express middleware that:

  • checks Authorization header
  • verifies JWT
  • attaches user to req.user

🎭 roleMiddleware(allowedRoles)

Protect routes based on user role.

roleMiddleware(["admin", "moderator"]);

🔑 hashPassword(password, saltRounds)

Hashes password using bcrypt.


🔓 comparePassword(password, hash)

Validates password against hash.


🧠 Design Philosophy

This package is built with:

  • Simplicity over complexity
  • Modularity over monoliths
  • Developer experience first
  • Drop-in usability in real backend apps

It is NOT a full authentication system.

Instead, it is a toolkit for building your own auth systems faster and cleaner.


⚠️ Important Notes

  • You must manage your own JWT secret securely
  • This package does NOT handle database storage
  • Designed for backend frameworks like Express

📌 Example Architecture Usage

Typical backend structure:

routes/
controllers/
middleware/
services/

Use jwt-auth-kit inside middleware + services layer.


🔥 Why use this?

Most projects repeatedly implement:

  • JWT logic
  • role checks
  • password hashing

This package removes that repetition and gives you a clean reusable layer.


🛠 Roadmap

Planned improvements:

  • TypeScript support
  • Refresh token utilities
  • Cookie-based auth helpers
  • Rate limiting middleware
  • OAuth helper extensions

👨‍💻 Author

Built by a developer focused on simplifying backend authentication systems and improving developer productivity.


📄 License

MIT