@samsch/use-knex-sessions
v0.0.2-private
Published
Sets up `express-session` and `connect-session-knex` with reasonable defaults, and adds `connect-flash`.
Downloads
4
Maintainers
Readme
useKnexSessions
Sets up express-session
and connect-session-knex
with reasonable defaults, and adds connect-flash
.
const express = require('express');
const knexFactory = require('knex');
const useKnexSessions = require('@local/use-knex-sessions');
const knex = knexFactory(require('./knexfile'));
const app = express();
const config = require('config.json'); // gitignore config file
useKnexSessions(app, knex, {
secret: config.sessionSecret, // Must be a random string at least 16 characters
cookie: {
// setting secure to false for development lets you use local http
// instead of needing https.
secure: config.env === 'prod',
},
});
The default options passed to express-session
and connect-session-knex
:
const defaults = {
resave: false,
saveUninitialized: false,
store: {
knex, // passed into useKnexSessions
createtable: false,
},
cookie: {
httpOnly: true,
secure: true,
sameSite: 'lax',
},
}