Serialization and deserialization using Passport.js

Hello, I’ve got one question concerning serialization and deserialization using passport.js in node.js. For example we serialize user basing on his id:

passport.serializeUser(function(user, done) {
  done(null, user.id);
});

And then we deserialize him also basing on his id:

passport.deserializeUser(function(id, done) {
  User.findById(id, function(err, user) {
    done(err, user);
  });
});

But how does the user give us the information about his ID everytime he opens the new tab or reload our website? Does the whole process is based on cookies?

Yep, in so many words it’s all about sessions and cookies. If you can spare the time this is an excellent and beginner-friendly write-up that explains how authentication in express works.

1 Like

Thank you for the link you gave, it was worth reading. Have you got some more articals about basics of backend programming?