1

I'm on a quest to update user's sessions when their user document is modified by someone other than them.

I was able to load the session and modify it, but is there a way to manually tell passport to reserialize the user? I need to refresh the data stored in it.

Normally you'd use req.login to re-log them in, but I don't have access to req.

stackers
  • 2,701
  • 4
  • 34
  • 66
  • How are you serializing and deserializing the user? It's common to just serialize the user's ID, then each request looks up the user's document to see if it has changed. – njwags Jun 09 '19 at 16:56
  • I serialize the whole user object because I didn't want multiple requests. I ended up just re-serializing it myself when the user is changed by modifying the session document. – stackers Jun 09 '19 at 17:36
  • @jwags looking up the user information in the database for every request adds unnecessary load when their information changes infrequently. Since you generally know when user information is changed (say for example user changes their name via api) you don't need to query the core DB every time, just update DB and session in the same call where they edit their info. Stackers care to answer your own question :)? – serakfalcon May 31 '22 at 05:00
  • Hey @serakfalcon, curious why are you adding a comment on a 3 year old question? I think the OP might need to add more explanation, or an example if they want specific help. – njwags Jun 01 '22 at 22:08
  • @jwags because I had the same question. SA questions are meant to be a resource for everyone with the same problem not just the OP. – serakfalcon Jun 01 '22 at 23:14
  • @serakfalcon That's fair! I'm afraid I don't think I understand the question. As my comment from 3 years ago asks, I would need you to show how you're serializing and deserializing to be of much help. My response from a week ago was meant to suggest that you can't add that kind of information in a comment. Maybe instead of adding a comment to an old post you could open a new question with an example? I'd love to help, if you do open a new question feel free to ping me. – njwags Jun 07 '22 at 23:00

0 Answers0