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
- [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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Understanding cookies and sessions3m 54s
-
(Locked)
Adding cookies and sessions to Express5m
-
(Locked)
Inspecting the session object2m 18s
-
Introduction to Passport1m 39s
-
(Locked)
Adding Passport to Express3m 55s
-
(Locked)
Setting up an authentication strategy for Passport5m 18s
-
(Locked)
Serializing and deserializing users3m 25s
-
(Locked)
Creating a login form with Passport5m 14s
-
(Locked)
Providing a logout link2m 1s
-
(Locked)
Authentication vs. authorization1m 23s
-
(Locked)
Protecting routes3m 35s
-
-
-
-