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

时间:2021-02-25 23:55:47

I understand that you can set the maxAge when starting up the app as follows:

我知道您可以在启动应用程序时设置maxAge,如下所示:

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

However, i would like to implement something along the lines of "remember me" setting, how would i go about doing that?

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

Thanks a lot :)

非常感谢 :)

Jason

贾森

1 个解决方案

#1


34  

You can set either expires or maxAge on the individual cookie belonging to the current user:

您可以在属于当前用户的单个cookie上设置expires或maxAge:

// 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;

See connect session documentation.

请参阅连接会话文档。

#1


34  

You can set either expires or maxAge on the individual cookie belonging to the current user:

您可以在属于当前用户的单个cookie上设置expires或maxAge:

// 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;

See connect session documentation.

请参阅连接会话文档。