Registry / security / redis-jwt

redis-jwt

JSON →
library1.4.0jsnpmunverified

Session management using Redis and JWT for horizontal scalability. Current version is 1.4.0. Provides both single-session and multi-session support per user, with token signing/verification and optional session data storage in Redis. Differentiates by combining JWT with Redis for session persistence and scaling, unlike pure JWT or pure Redis-session approaches. Requires Node >=6.x and Redis >=3.x.

npm install redis-jwt
INSTALL
IMPORT
SIG · REDIS-JWT
R
redis-jwt
securityjavascriptv1.4.0
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 RedisJwt from 'redis-jwt'
const RedisJwt = require('redis-jwt').default
Default export, ESM style. CommonJS users should use `const RedisJwt = require('redis-jwt')`.
RedisJwt
const RedisJwt = require('redis-jwt')
const { RedisJwt } = require('redis-jwt')
CommonJS require; the module exports the class directly, not as a named export.
RedisJwt (TypeScript)
import RedisJwt from 'redis-jwt'
import * as RedisJwt from 'redis-jwt'
TypeScript users should use default import. No type definitions published; may need @types/redis-jwt or custom declarations.

Basic sign and verify using RedisJwt with default settings and custom TTL/token data.

import RedisJwt from 'redis-jwt'; const r = new RedisJwt({ host: '127.0.0.1', port: 6379, secret: 'my_secret_key', multiple: false }); r.sign('user123', { ttl: '15 minutes', dataToken: { role: 'admin' } }) .then(token => { console.log('Token:', token); return r.verify(token); }) .then(decoded => { console.log('Decoded:', decoded); }) .catch(err => { console.error('Error:', err); });
Debug
Known issues
deprecatedNode.js version 6 is end-of-life; recommended version is 8 or higher.
fix
Upgrade Node.js to version 8 or later.
affects: <6
gotchaThe `multiple` option defaults to `false`, meaning only one active session per user ID. If you need concurrent sessions, set `multiple: true`.
fix
Initialize RedisJwt with `multiple: true` if multiple sessions per user are required.
affects: all
gotchaThe `secret` option is required; omitting it will cause errors during sign/verify.
fix
Always provide a `secret` string when creating an instance.
affects: all
gotchaTTL must be a string like '15 minutes', '1 hour', etc. Using a number or unsupported format may break.
fix
Use a string with unit (e.g., '15 minutes', '1 hour') for TTL.
affects: all
gotchaThe `verify` method with second argument `true` fetches session data from Redis. This adds latency and requires Redis to be available.
fix
Only use `verify(token, true)` when you need session data from Redis; for simple token validation, omit the second argument.
affects: all
breakingVersions prior to 1.0.0 used a different API. This package follows semver, so check changelog for migration.
fix
Upgrade to >=1.0.0 and adapt code to the new API: new RedisJwt(options), sign/verify methods.
affects: <1.0.0
Errors
Common errors & fixes
Error: secret is required
Missing `secret` option in constructor.
fix
Add `secret: 'your-secret-key'` to the options object.
Error: Redis connection refused
Redis server is not running or host/port is incorrect.
fix
Ensure Redis is running on the specified host and port. Check firewall settings.
TypeError: r.sign is not a function
Using wrong import style (e.g., destructuring named export instead of default import).
fix
Use `import RedisJwt from 'redis-jwt'` (ESM) or `const RedisJwt = require('redis-jwt')` (CJS), then create an instance with `new RedisJwt(...)`.
Error: jwt malformed
Token string is invalid or tampered with.
fix
Verify the token was generated by the same secret. Check for extra spaces or truncation.
Upgrade
Version history
1.4.0latest on npm
Audit
Dependencies
redisrequiredRedis client for session storage
jsonwebtokenrequiredJWT signing and verification
Agent activity
20 hits · last 30 days
node
20
Resources