简体   繁体   English

更新快速会话

[英]Updating express-session sessions

So what I'm trying to do is when the users accesses the page it will fetch their user profile from the mongodb database and then update the users session with the users profile. 所以我想做的是,当用户访问该页面时,它将从mongodb数据库中获取其用户配置文件,然后使用用户配置文件更新用户会话。

Right now I'm currently using the following packages for sessions: 现在,我目前正在使用以下程序包进行会话:
- express-socket.io-session (allows me to access cookies through socket.io) -express-socket.io-session(允许我通过socket.io访问cookie)
- express-session -快速会议
- connect-mongo (Allows me to store sessions in a mongodb database) -connect-mongo(允许我将会话存储在mongodb数据库中)

Heres what I've tried to use to get the users cookies to update 这是我试图用来获取用户Cookie的更新

req.session.reload(function(err) {
  // session updated 
})

Typically you save object (eg user profile) in session and session is stored in mongo. 通常,您将对象(例如,用户配置文件)保存在会话中,并且会话存储在mongo中。
Cookie on client contains only expires date and session id. 客户端上的Cookie仅包含过期日期和会话ID。 With each request you get cookie with session ID and can obtain session from mongo by this ID. 对于每个请求,您都会获得带有会话ID的cookie,并可以通过此ID从mongo获取会话。
When you update any field in session it will be resaved in mongo. 当您更新会话中的任何字段时,它将在mongo中重新保存。
So you don't need 'reload'. 因此,您不需要“重新加载”。 You can just assign in like req.session.user = user . 您可以像req.session.user = user这样分配。
Docs 文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM