How to set the session timeout after log in passportjs?

Problem

I want to set a session timeout after log in using passportjs. How to set the maxAge for the session using passportjs. What is the default max age for the session that passportjs provide?

Problem courtesy of: Jetson John

Solution

That is handled via Connect's session middleware, so for example:

.use(connect.session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))

The documentation has other useful bits that are worth reading for understanding session handling.

Solution courtesy of: user1218070

Discussion

You need to set the lifetime of the session cookie for express.session like the following example:

app.use(express.session({
             secret : 'your_cookie_secret',
             cookie:{_expires : 60000000}, // time im ms
             })
        ); 

For testing I recommend a shorter expires time.

Discussion courtesy of: Bernhard

This recipe can be found in it's original form on Stack Over Flow.