panthera-session
v0.1.3
Published
Session middleware for PantheraJS applications.
Downloads
1
Readme
panthera-session
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 tosession-id
.tableName
: The name of the database table to use for storing and retrieving session records. Defaults tosessions
.cookieOpts
: An object specifying options to use when setting and retrieving cookies. Supports all options used bycookies
, defaultingoverwrite
andsigned
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;
});