sessy

Implementable session interface

npm install sessy
1 downloads in the last week
4 downloads in the last month

Sessy (WIP) Build Status

A implementable session interface. Supports session objects as well as CSRF tokens. Born out out of https://github.com/senchalabs/connect/issues/935.

  • This is low-level, meaning it's just a constructor and a bunch of methods. You would have to create your own middleware for your own framework such as connect/express.
  • Most methods and properties on the prototype are implementable, meaning you can change things however you'd like.
  • All async methods return a thunk for easy integration with generator-based control flow frameworks such as co

API

Session(req, res)

Create a new session instance for a particular request.

app.use(function (req, res, next) {
  // Only the session constructor
  req._session = new Session(req, res)

  // Get the actual session object and attach it to
  req._session.getSession(function (err, session) {
    if (err)
      return next(err)

    req.session = session
    next()
  })
})

Session.extend([prototype])

Creates a new, yet equivalent, Session constructor. Do this so that you don't butcher the original prototype. prototype are additional properties to attach to the new prototype. The following are equivalent:

var App1Session = Session.extend({
  maxAge: 60
})

var App1Session = Session.extend()
App1Session.prototype.maxAge = 60

License

The MIT License (MIT)

Copyright (c) 2013 Jonathan Ong me@jongleberry.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

npm loves you