thorken
v1.3.0
Published
Redis and JWT token based session manager.
Downloads
10
Readme
thorken
Redis
and JWT
token based session manager.
Usage
You need redis to use this package.
npm install --save thorken
Configure
var Thorken = require('thorken')
var session = new Thorken({
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) { ... })
Extend
The second ttl parameter is optional.
session.extend('token', 7200)
.then(function (expiresAt) { ... })
Destroy
session.destroy('token')
.then(function (isSuccess) { ... })
Cleanup
For manual cleanup.
To clear only expired sessions
session.cleanup().then(function () { ... })
To clear every session
session.cleanup(true).then(function () { ... })
Get user's sessions
session.getByUserId('1').then(function (sessions) { ... })
Destroy user's sessions
session.destroyUser('1').then(function (isSuccess) { ... })
Server connectors
Koa middleware
var app = require('koa')()
var Thorken = require('thorken')
var protect = require('thorken/src/koa')
var session = new Thorken({ ... })
app.use(protect(session, {
[extend]: true
}))