I believe something is wrong with your serialization / deserialization.
When serializing, you need to specify how you are going to serialize the user. According to your code, you use user IDs to serialize them. And this is what will be used for deserialization. Thus, you should expect only the identifier from the input parameters, and you need to find the user associated with this identifier and pass it to the callback.
This will be what you should do:
passport.serializeUser(function(user, done){
done(null, user.id)
})
passport.deserializeUser(function(id, done){
User.findById(id, function(err, user){
done(err, user)
})
})
source
share