From the course: Advanced Express

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Serializing and deserializing users

Serializing and deserializing users

From the course: Advanced Express

Start my 1-month free trial

Serializing and deserializing users

- [Instructor] When it comes to serialization, deserialization of users, it's up to us to decide what to store in the session. We could store the whole user object, but this would also mean that when a user is deleted or data is changed, the stored user object in the session would still be the same. It's better to just store the user ID and use this ID to retrieve the user from the database for every time the session is loaded. So, let's implement this serialization and deserialization now. I will add here, after line 19, passport.serializeUser and this function gets the actual user as first argument and the done callback. And all we do here now is we return done with null error, but a user._id. And we see that eslint is now complaining a bit here. Here on line 21, it's telling us that the block statement could be optimized. So, let's let eslint just fix that. So, I'm clicking into this line, and do you see now this light bulb showing up? And there I select Fix this arrow-body style…

Contents