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.
JWTRedisSession
✓ import JWTRedisSession from 'jwt-redis-session';
✗ const JWTRedisSession = require('jwt-redis-session');
The package exports a single function via module.exports; default import is correct in ESM. CommonJS require also works, but the import style is preferable in modern projects.
options object
✓ const session = JWTRedisSession({ client: redisClient, secret: 'mysecret' });
✗ const session = new JWTRedisSession({ ... });
JWTRedisSession is a factory function, not a constructor. Do not use 'new'.
requestArg usage
✓ // JWT is read from req.query.accessToken, req.body.accessToken, or x-access-token header (default option).
app.use(JWTRedisSession({ requestArg: 'accessToken' }));
✗ // Assuming requestArg is 'token' but expecting header 'x-token'; shorthand for camelBack: 'jwtToken' expects header 'x-jwt-token'
The header name is derived by converting requestArg to lowercase and prefixing 'x-'. For example, 'accessToken' yields 'x-access-token'.
Minimal Express app using jwt-redis-session with Redis for JWT-based session management.
const express = require('express');
const redis = require('redis');
const JWTRedisSession = require('jwt-redis-session');
const app = express();
const redisClient = redis.createClient({ url: process.env.REDIS_URL || 'redis://localhost:6379' });
app.use(require('body-parser').json());
app.use(JWTRedisSession({
client: redisClient,
secret: process.env.JWT_SECRET || 'changeme',
keyspace: 'sess:',
maxAge: 86400,
algorithm: 'HS256',
requestKey: 'jwtSession',
requestArg: 'jwtToken'
}));
app.post('/login', (req, res) => {
// Simulate user login: store data in session
req.jwtSession.user = { id: 1, username: 'test' };
req.jwtSession.create((err, token) => {
if (err) return res.status(500).send(err);
res.json({ token });
});
});
app.get('/protected', (req, res) => {
// Session auto-populated from JWT in request
if (!req.jwtSession.user) return res.status(401).send('Unauthorized');
res.json({ user: req.jwtSession.user });
});
app.listen(3000);
Errors
Common errors & fixes
TypeError: Cannot read property 'create' of undefined
The session object is not attached to the request because the middleware was not applied or the requestKey option is misconfigured.
fixEnsure app.use(JWTRedisSession(...)) is called with correct options, and use the correct requestKey (default 'session' but may be customized).
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server is not running or the client configuration is wrong.
fixStart Redis server or set REDIS_URL environment variable to a valid Redis connection string. Provide a functional redisClient instance.
TypeError: secret must be a string or buffer
The 'secret' option is missing or is not a string.
fixProvide a string secret: JWTRedisSession({ secret: 'your-secret-key', ... }) Audit
Dependencies
redisrequiredRequired to create a Redis client for session storage; the module expects a pre-configured client.
expressoptionalCommonly used as Connect/Express middleware; while not a direct dependency, it is designed for Connect-compatible frameworks.