Redis
and JWT
token based session manager.
You need redis to use this package.
npm install --save thorken
var Thorken = require('thorken')
var session = new Thorken({
jwtSecret: 'secret',
[namespace]: 'ts',
[redis]: ioredisInstance,
[cleanupManual]: false
})
session.create({
uid: '1',
[ttl]: 7200,
[ip]: '127.0.0.1'
})
.then(function (jwtToken) { ... })
session.get('token')
.then(function (session) { ... })
session.extend('token', 7200)
.then(function (expiresAt) { ... })
session.destroy('token')
.then(function (isSuccess) { ... })
For manual cleanup.
To clear only expired sessions
session.cleanup().then(function () { ... })
To clear every session
session.cleanup(true).then(function () { ... })
// TODO
session.destroyUser('1').then(function (isSuccess) { ... })
var app = require('koa')()
var Thorken = require('thorken')
var protect = require('thorken/src/koa')
var session = new Thorken({ ... })
app.use(protect(session, {
[extend]: true
}))