Michael Seltenreich
Michael Seltenreich

Reputation: 3488

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:

app.use(session({
    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?

Upvotes: 3

Views: 3803

Answers (1)

Ravi Shankar Bharti
Ravi Shankar Bharti

Reputation: 9268

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

app.use(express.session({
    cookie : {
        maxAge: 1000* 60 * 60 *24 * 365
    },
    store : new MongoStore({mongooseConnection:mongoose.connection})
});
//.....
app.use(passport.session());

Upvotes: 8

Related Questions