connect-session-knex
connect-session-knex copied to clipboard
saving session info in the postgres DB
Hi All, I'm using express-session to store the session to a postgres table. If I use resave: true, saveUninitialized: true, then it's creating a separate session entry in DB for each request. However if I give resave: false, saveUninitialized: false, then it's not creating any entry in the DB, Any idea on how to fix this issue.
Here is the session config:
const Knex = require("knex");
const KnexSessionStore = require("connect-session-knex")(session);
const knex = Knex({
client: "pg",
connection: {
host: "127.0.0.1",
user: "test",
password: "test",
database: "mydb",
},
});
const sessionStore = new KnexSessionStore({
knex,
tablename: "sessions", // optional. Defaults to 'sessions'
});
app.use(
session({
sessionStore,
secret: "keyboard cat",
resave: true,
saveUninitialized: true,
cookie: { secure: false, maxAge: 30 * 24 * 60 * 60 * 1000 },
})
);