Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

saving session info in the postgres DB #104

Open
arunkumar413 opened this issue May 20, 2024 · 0 comments
Open

saving session info in the postgres DB #104

arunkumar413 opened this issue May 20, 2024 · 0 comments

Comments

@arunkumar413
Copy link

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 },
  })
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant