简体   繁体   中英

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.

Right now I'm currently using the following packages for sessions:
- express-socket.io-session (allows me to access cookies through socket.io)
- express-session
- connect-mongo (Allows me to store sessions in a mongodb database)

Heres what I've tried to use to get the users cookies to update

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

Typically you save object (eg user profile) in session and session is stored in mongo.
Cookie on client contains only expires date and session id. With each request you get cookie with session ID and can obtain session from mongo by this ID.
When you update any field in session it will be resaved in mongo.
So you don't need 'reload'. You can just assign in like req.session.user = user .
Docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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