changing maxAge for session cookies

1,512 views
Skip to first unread message

gocsurams

unread,
Jan 28, 2012, 5:59:32 PM1/28/12
to nodejs
I am starting my http server with the following session option:
app.use(express.session({ secret: 'mysecret', cookie: {maxAge:
3600000} }));
Can I change the maxAge attribute later without restarting the server.
If so, how do I do this?

Thanks,
Ashok

mscdex

unread,
Jan 28, 2012, 11:00:04 PM1/28/12
to nodejs
On Jan 28, 5:59 pm, gocsurams <gocsur...@gmail.com> wrote:
> Can I change the maxAge attribute later without restarting the server.
> If so, how do I do this?

What about setting 'cookie' to an object with a 'maxAge' getter?:

app.use(express.session({
secret: 'mysecret',
cookie: {
get maxAge() {
if (somelogic)
return 1800000;
else
return 3600000;
}
}
}));

tjholowaychuk

unread,
Jan 30, 2012, 11:09:04 AM1/30/12
to nodejs
there's also req.session.cookie.maxAge= which is request-specific

gocsurams

unread,
Jan 30, 2012, 2:09:53 PM1/30/12
to nodejs
It appears to me that the logic in getMaxAge() is executed once when
the
app.use() statement is encountered and thereafter the maxAge is
set to the value returned by maxAge(). What I was looking for is the
ability to change the cookie maxAge some time after the server was
started.

Thanks,
Ashok

C. Mundi

unread,
Jan 30, 2012, 6:44:35 PM1/30/12
to nod...@googlegroups.com

Um...TJ, I have dumb question here... Are you saying that express creates each req with a 'snapshot' copy of the session cookie and that these snapshots can be modified independently, without affecting the session cookie?

I hope I asked that the right way...

Thanks

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

tjholowaychuk

unread,
Jan 30, 2012, 7:03:34 PM1/30/12
to nodejs
@Mundi the object passed to the middleware is only the default, you
can manipulate the .cookie object per-request as
well, .maxAge, .secure, .httpOnly etc

On Jan 30, 3:44 pm, "C. Mundi" <cmu...@gmail.com> wrote:
> Um...TJ, I have dumb question here... Are you saying that express creates
> each req with a 'snapshot' copy of the session cookie and that these
> snapshots can be modified independently, without affecting the session
> cookie?
>
> I hope I asked that the right way...
>
> Thanks

C. Mundi

unread,
Jan 30, 2012, 7:20:09 PM1/30/12
to nod...@googlegroups.com

@TJ ... Thank you for your reply.  This opens my eyes.

Reply all
Reply to author
Forward
0 new messages