Home

Awesome

toa-session

Session middleware for toa, inspired by generic-session.

NPM version Build Status Downloads

toa

Demo

use as middleware:

const Toa = require('toa')
const session = require('toa-session')()

const app = new Toa()
app.use(function () {
  if (this.path === '/favicon.ico') return
  if (this.path === '/delete') this.session = null
  else this.session.name = 'test'

  this.body = {
    path: this.path,
    session: this.session,
    sessionId: this.sessionId
  }
})

app.use(session)
app.listen(3000)

use as module:

const Toa = require('toa')
const session = require('toa-session')()

const app = new Toa()(function *() {
  if (this.path === '/favicon.ico') return
  yield session

  if (this.path === '/delete') this.session = null
  else this.session.name = 'test'

  this.body = {
    path: this.path,
    session: this.session,
    sessionId: this.sessionId
  }
})

app.listen(3000)

Installation

npm install toa-session

API

const session = require('toa-session');

app.use(session([options]))

const defaultCookie = {
  httpOnly: true,
  path: '/',
  overwrite: true,
  signed: true,
  maxAge: 24 * 60 * 60 * 1000 // ms
};

Session Store

You can use any other store to replace the default MemoryStore, it just needs to follow this api:

the api needs to return a Promise, Thunk or generator.

And use these events to report the store's status.

Licences

(The MIT License)