0.1.7 • Published 7 years ago

trek-sessions v0.1.7

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

sessions

Sessions middleware.

Installation

$ npm install trek-sessions --save

Examples

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)

API

Sessions

Store

Map like

const store = new Store(provider, {
  exports: 86400,
  prefix: 'trek:sess:'
})
  • provider

    The sessions are storing on the provider.

  • touch(cookie)

    Retures a session.

  • previx(sid)

    Adds a prefix to sid.

  • async clear()

    Removes all sessions.

  • async delete(sid)

    Removes a session by the sid.

  • async has(sid)

    Returns a boolean asserting whether a session has been associated to the sid in the store or not.

  • async get(sid)

    Returns the session associated to the sid, or undefined if there is none.

  • async set(sid, sess)

    Sets the session for the sid in the store.

Provider

Badges

Build Status codecov MIT


fundon.me  ·  GitHub @fundon  ·  Twitter @_fundon

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.0

8 years ago