Michael Seltenreich Michael Seltenreich - 1 year ago 77
Node.js Question

Why is my session expiring every time I close the browser?

I set up the session maxAge of express like documented.

Here is my code:

secret: process.env.SESSION_SECRET,
saveUninitialized: true,
resave: true,
maxAge: 1000* 60 * 60 *24 * 365,
store: new MongoStore({mongooseConnection:mongoose.connection})

But every time I close the browser, I find myself logged out.

Also, note that I am using Passport local, facebook, and google authentications.

They all expire.

In the console, I can see that the connect.sid in the expires/maxAge section lists "Session" while other cookies have dates...

What am I doing wrong?

Answer Source

you need to configure your express-session, and set maxAge on session-cookie

    cookie : {
        maxAge: 1000* 60 * 60 *24 * 365
    store : new MongoStore({mongooseConnection:mongoose.connection})