Sessions middleware.
$ npm install trek-sessions --save
const Engine = require('trek-engine')
const sessions = require('trek-sessions')
async function start (port = 3000) {
const app = new Engine()
app.config.set('cookie', {
keys: ['trek', 'engine']
})
app.use(sessions({
cookie: {
signed: false,
maxAge: 60 * 1000 // 1 minutes
}
}))
app.use((ctx, next) => {
ctx.res.body = ctx.session
})
app.run(port)
}
start().catch(console.error)Map like
const store = new Store(provider, {
expires: 86400,
prefix: 'trek:sess:'
})-
providerThe
sessionsare storing on theprovider. -
previx(sid)Adds a prefix to
sid. -
async clear()Removes all sessions.
-
async delete(sid)Removes a
sessionby thesid. -
async has(sid)Returns a boolean asserting whether a
sessionhas been associated to thesidin thestoreor not. -
async get(sid)Returns the
sessionassociated to thesid, orundefinedif there is none. -
async set(sid, sess)Sets the
sessionfor thesidin the store.