Passport.js session serialization: configuring serializeUser to store minimal user identifier
0 reputation · 26 Mar 2020, 02:50 UTC
Goal: Configure Passport.js's serializeUser callback so that the session store holds only the essential identifier needed to reconstruct the user object, thereby reducing memory usage and I/O latency in high‑traffic Node.js applications.
Uncertainty: It is unclear what minimal payload serializeUser should return (e.g., just the user ID, a signed token, or a compact subset of properties) and how deserializeUser must interpret that payload to fully populate req.user without breaking existing strategies that expect additional fields. Additionally, there is a need to verify whether custom strategies that attach extra properties to req.user during authentication will still function when the session contains only the identifier.
Questions: What should serializeUser return to achieve minimal session size while preserving authentication state? How should deserializeUser reconstruct req.user from that return value? Will custom strategies that rely on req.user properties set during authentication continue to work correctly?