如何在express中设置单个会话maxAge?

时间:2012-03-15 06:11:02

标签: node.js express session-cookies

我了解您可以在启动应用时设置maxAge,如下所示:

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

但是,我想按照“记住我”的设置实施一些东西,我该怎样做呢?

非常感谢:)

杰森

1 个答案:

答案 0 :(得分:40)

您可以在属于当前用户的个人Cookie上设置expiresmaxAge

// This user should log in again after restarting the browser
req.session.cookie.expires = false;

// This user won't have to log in for a year
req.session.cookie.maxAge = 365 * 24 * 60 * 60 * 1000;

请参阅connect session documentation