Code: (from The Net Ninja: https://www.youtube.com/watch?v=-PuMp5tQ8Jw&list=PL4cUxeGkcC9jdm7QX143aMLAqyM-jTZ2x&index=15&ab_channel=TheNetNinja)
passport.serializeUser((user,done) => {
done(null, user.id);
});
//...
// new user created
done(null, newUser);
Questions:
- how “serializeuser” method knows about user object? it doesn’t have access to it? how does it access to user?
- is “serializeUser method some kinda event listener? whenever done is called, it will do something.
- why don’t we directly call done(null, user.id) after a new user is created.
- how done(null, newUser) triggers serializeUser method? I cannot understand it.
Note: I know how callback functions work, but this one is different. I cannot understand how serialize function gets called after done function is called. And I cannot understand how serialize function can access to user? I've searched but cannot find explanation.