
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
shelf-jwt-sessions
Advanced tools
A simple tool for defining user session model classes in redis using shelf and jwt
Define user session model classes with ttl in redis using jwt and shelf.
For when you need to store volatile user sessions, with all that useful info you need, but don't want to go through the pain of creating special cron jobs to clear them. Creating new sessions should be easy and authenticating requests should be fast, so, here you go, jwt + redis, perfect combo!
Shelf sessions uses joi for schema validation and node-jsonwebtoken lib for issuing tokens and validating them.
const ShelfSessions = require('shelf-jwt-sessions')
const Crypto = require('crypto')
const Joi = require('joi')
const secret = Crypto.randomBytes(128)
let MyShelf = ShelfSessions('test', secret, {
algorithm: 'HS256',
subject: 'yolo',
issuer: 'me'
})
let MyModel = MyShelf.extend({
name: 'basic-user',
props: {
userAgent: Joi.string()
}
})
MyModel.createSession({
userId: 'me',
scopes: ['default'],
userAgent: 'stuff from the header'
}, (err, result) => {
if (err) throw err
MyModel.authenticate(result.jwt, console.log)
})
ShelfSessions(name, secretOrPrivateKey, [options])Initiate a ShelfSessions instance.
name will be the name used to instantiate ShelfsecretOrPrivateKey secret/private key used to sign the JWT's as described by the node-jsonwebtoken library. It must be a string or a buffer.[options] series of optional parameters used by node-jsonwebtoken and Shelf
[algorithm] algorithm used to sign the jwt[audience] audience claim[subject] subject claim[issuer] issuer claim[headers] additional headers as specified by node-jsonwebtoken[ttl] sessions ttl in seconds. Defaults to 72 hours[shelf] an already inited shelf instance (will override connection options to instantiate Shelf)[host] redis host used by Shelf[port] redis port used by Shelf[password] redis password used by Shelf[defaultProps] an optional json object whose keys should be Joi objects. This is used to extend the default session schema and be used on all the .extend() calls. The default schema will be:{
jwt: Joi.string().required(),
userId: Joi.string().required(),
scopes: Joi.array().min(1).required()
}
You can extend the schema at will but this three keys must always exist..extend(model)Generate a SessionModel schema similar to what you would do with a regular Shelf instance. The provided schema will then be used to operate on the specified models.
model a model similar to what you would use in Shelf.extend(model)
name a mandatory name for the schema.[props] an optional json object whose keys should be Joi objects, used to extend the base user model according to the defaultProps.** Note: ** no keys array is provided to act as Redis key, as it will always be the jwt.
SessionModelThe result of the .extend() call. This will allow to make operations based on the schemas and options previously provided.
.deleteSession(token, callback)Delete the sessions associated with the token. The callback will be called with an error in case of failure.
token jwt tokencallback a callback function.createSession(session, callback)Creates a session based on the given session object. The callback will be called as - callback(error, resultSession) - being that, if successful, the provided resultSession will be a Shelf Model with all the normal operations associated to it.
session a session json objectcallback a callback function.authenticate(token, callback)Given a jwt, this method verifies it and returns the correspondent session Shelf Model stored in Redis. The callback will be called as - callback(error, resultSession)
token jwt tokencallback a callback functionWe use standard js.
In order to run the tests you should have an Redis instance running locally.
MIT
FAQs
A simple tool for defining user session model classes in redis using shelf and jwt
The npm package shelf-jwt-sessions receives a total of 0 weekly downloads. As such, shelf-jwt-sessions popularity was classified as not popular.
We found that shelf-jwt-sessions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.