Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
lihaoquan
12,045 PointsNodeJs Mozilla Middleware - client-sessions - activeDuration field
I've started using client-sessions, a middleware for session management for nodeJs by Mozilla.
Below is the code to setup a session :
app.use(session({
cookieName: 'session',
secret: 'super-secret',
duration: 30 * 60 * 1000,
activeDuration: 5 * 60 * 1000
});
I know that duration field sets the duration before the cookie expires. However, I'm not sure how activeDuration works. I know it lengthens a user's cookie expiration time by 5 minutes if the user is active, but does it stack? e.g ( duration left: 29 minutes, user request a page, lengthens session by 5 minutes, total minutes left: 34 minutes, user request another page, lengthens session by 5 minutes, total minutes left: 39 minutes ) or does it add 5 minutes only when duration falls below 30 minutes?
1 Answer
Colin Bell
29,679 PointsFrom github page I think you're referring to:
// if expiresIn < activeDuration, the session will be extended by activeDuration milliseconds
Ā
Looks like it extends it by activeDuration's value, but only if it time left to expiration is less than activeDuration's value.
So if activeDuration is set to 5 minutes, if the cookie's timer reaches 4:59 it will bump up to 9:59 and won't be bumped up again until it reaches 4:59 again.
lihaoquan
12,045 Pointslihaoquan
12,045 PointsThanks, I'll learn to read the documentations haha.