panthera-session

0.1.3 • Public • Published

panthera-session

npm Build Status Coverage Dependency Status Supported Node.js version MIT licensed

Session middleware for PantheraJS applications. Intended for use alongside panthera-mysql-adapter.

Installation

npm install panthera-session

Usage

const koa = require('koa');
const session = require('panthera-session');

let app = koa();

/*
app.context.db = {
  execute: function {...}
};
 */

let options = {
  key: 'cookieName',
  tableName: 'sessions',
  cookieOpts: {
    overwrite: true,
    signed: true
  }
};

app.use(session(app, options));
app.use(function *(next) {
  // this.session...
  yield* next;
});

app.listen(3000);

options

The options argument is optional and supports the following properties.

  • key: The key name of the cookie to set and retrieve. Defaults to session-id.
  • tableName: The name of the database table to use for storing and retrieving session records. Defaults to sessions.
  • cookieOpts: An object specifying options to use when setting and retrieving cookies. Supports all options used by cookies, defaulting overwrite and signed to true.

#regenerateSessionId

Regenerates the existing session id, setting the appropriate cookie. Does not touch any of the other data in the session.

app.use(session(app, options));
app.use(function *(next) {
  yield this.regenerateSessionId();
  yield* next;
});

#setSessionUserId

Sets the session user id, regenerating the existing session id. Intended for user authorization.

app.use(session(app, options));
app.use(function *(next) {
  yield this.setSessionUserId(1);
  yield* next;
});

Readme

Keywords

none

Package Sidebar

Install

npm i panthera-session

Weekly Downloads

0

Version

0.1.3

License

MIT

Last publish

Collaborators

  • pantherajs