session is getting expired after closing browser in express.js

59 views Asked by At

I used both cookie-session and express-session, I also specified maxAge but still, it's no use.


const expressSession = require("cookie-session");


const IN_PROD = process.env.NODE_ENV === "production";

app.use(
  expressSession({
    name: process.env.SESSION_NAME, //setting custom name
    resave: false, // do not store if it never modified
    secret: process.env.SESSION_SECRETE, // secrete key which we dont't want expose to client
    saveUninitialized: false, //dont save the session which is empty

    cookie: {
      maxAge: 30 * 24 * 60 * 60 * 1000, //Session liftime
      sameSite: true,
      secure: IN_PROD, //set true when application is in production mode and false when it is in development mode
    },
  })
);

0

There are 0 answers