softoken
v1.0.1
Published
Redis and JWT token based session manager.
Downloads
4
Readme
Softoken
Redis
and JWT
token based session manager.
Usage
You will need redis to use this package.
npm install --save softoken
Configure
var Softoken = require('softoken')
var session = new Softoken({
jwtSecret: 'secret',
[namespace]: 'ts',
[redis]: ioredisInstance,
[cleanupManual]: false
})
Create
session.create({
uid: '1',
[ttl]: 7200,
[ip]: '127.0.0.1'
})
.then(function (jwtToken) { ... })
Get
session.get('token')
.then(function (session) { ... })
Destroy
session.destroy('token')
.then(function (isSuccess) { ... })
Extend
The second ttl parameter is optional.
session.extend('token', 7200)
.then(function (expiresAt) { ... })
Get user's sessions
session.getByUserId('1').then(function (sessions) { ... })
Destroy user's sessions
session.destroyUser('1').then(function (isSuccess) { ... })
Cleanup
For manual session cleanup.
To clear only expired sessions
session.cleanup().then(function () { ... })
To clear every session
session.cleanup(true).then(function () { ... })