After a successful authentication, passport,js sets req.user. But in some of my routes, i update the user object in mongodb database. When i try to reach it again from req.user, i get the outdated version. Doesn't passport.js automatically update the req.user object?
Or what is the appropriate way of doing this? ( I'm using express.js 3.x , mongodb )
Thanks
At last, i found where the problem is. I was not deserializing user :
passport.deserializeUser(function(obj, done) {
db.User.findOne(obj._id, function (err, user) {
done(err, user);
});
});
Now it is updated at every request. Also one minor thing that you can come across, if you don't want to hit db for deserializing the user object for static resources, just move the conf in app.js to up in the middleware order
app.use(express.static(path.join(__dirname, 'public')));
Most helpful comment
At last, i found where the problem is. I was not deserializing user :
passport.deserializeUser(function(obj, done) {
db.User.findOne(obj._id, function (err, user) {
done(err, user);
});
});
Now it is updated at every request. Also one minor thing that you can come across, if you don't want to hit db for deserializing the user object for static resources, just move the conf in app.js to up in the middleware order
app.use(express.static(path.join(__dirname, 'public')));