Registry / security / jwt-redis

jwt-redis

JSON →
library7.0.3jsnpmunverified

A JSON Web Token (JWT) library that extends jsonwebtoken by adding Redis-backed token revocation. v7.0.3 wraps the full jsonwebtoken API with methods sign, verify, decode, and destroy; the destroy method removes a token's jti from Redis, making it immediately invalid. It requires Redis client (node-redis v4+). Uses ESM by default; ships TypeScript definitions. Key differentiator: ability to revoke tokens before expiry, unlike jsonwebtoken itself.

npm install jwt-redis
INSTALL
IMPORT
SIG · JWT-REDIS
J
jwt-redis
securityjavascriptv7.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import JWTR from 'jwt-redis';
const JWTR = require('jwt-redis'); // or: const JWTR = require('jwt-redis').default;
Default export: use ESM or the .default property in CommonJS.
JWTR
import JWTR from 'jwt-redis';
import { JWTR } from 'jwt-redis';
The class is exported as default; named import is not available.
JwtRedis
import JWTR from 'jwt-redis';
import { JwtRedis } from 'jwt-redis';
The type for the library instance is not exported as a named symbol; use the class itself or the default import.

Shows sign, verify, and destroy operations with ESM imports and async/await.

import { createClient } from 'redis'; import JWTR from 'jwt-redis'; async function main() { const redisClient = createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:6379' }); await redisClient.connect(); const jwtr = new JWTR(redisClient); const secret = 'my-secret'; const payload = { userId: 123 }; try { const token = await jwtr.sign(payload, secret, { expiresIn: '1h' }); console.log('Token:', token); const decoded = await jwtr.verify(token, secret); console.log('Decoded:', decoded); // Revoke the token by its jti await jwtr.destroy(decoded.jti); console.log('Token destroyed'); } catch (err) { console.error(err); } finally { await redisClient.quit(); } } main();
Debug
Known issues
breakingBreaking change: Redis client constructor argument changed from client to both client and options. Ensure you pass a valid connected Redis client.
fix
Use new JWTR(redisClient) with a connected Redis client; do not pass legacy client types.
affects: >=7.0.0
deprecatedThe library previously supported ioredis in older versions; v7 only supports redis (node-redis v4).
fix
Migrate from ioredis to the redis package (v4+).
affects: >=7.0.0
gotchaThe default export must be imported with .default in CommonJS: const JWTR = require('jwt-redis').default;
fix
When using require, always add .default.
affects: all
gotchaThe sign method adds a jti claim automatically if not provided; the jti is used for destroy and must be unique.
fix
Either let the library generate jti or provide your own unique value in payload.
affects: all
gotchaThe verify method checks Redis for the jti; if the token is destroyed, verify will throw an error even if the JWT signature is valid.
fix
Handle the 'jwt revoked' error in your application logic.
affects: all
Errors
Common errors & fixes
Error: Please provide redisClient
JWTR constructor called without arguments or with undefined client.
fix
Pass a connected Redis client instance: const jwtr = new JWTR(redisClient);
TypeError: jwt.sign is not a function
Incorrect import: used named import instead of default import.
fix
Use import JWTR from 'jwt-redis'; then const jwtr = new JWTR(redis); jwtr.sign(...);
JWTRevokedError: The token has been revoked
Token's jti was destroyed or does not exist in Redis.
fix
Ensure the token has not been destroyed, or verify that the Redis prefix matches (default 'jwt_label:').
Upgrade
Version history
7.0.3latest on npm
Audit
Dependencies
redisrequiredPeer dependency; jwt-redis requires a Redis client to store and check token labels for revocation.
Agent activity
25 hits · last 30 days
node
24
Amazon
1
Resources