Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion backend/config/passportConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ passport.serializeUser((user, done) => {
});

// Deserialize user (retrieve user from session)
// .select('-password -__v') excludes the bcrypt hash from req.user so it
// cannot be accidentally serialized into an API response.
// .lean() returns a plain object instead of a Mongoose document, preventing
// model methods from being accessible on req.user.
passport.deserializeUser(async (id, done) => {
try {
const user = await User.findById(id);
const user = await User.findById(id).select('-password -__v').lean();
done(null, user);
} catch (err) {
done(err, null);
Expand Down
Loading