Expressjs Passportjs De-serializes User Object For Every Request To A Route
I have a ExpressJS app that is using Passportjs to authenticate with Facebook and everything is working as expected exception for one issue. I have vehicle.js under /routes/ which
Solution 1:
You can wrap the passport middleware inside a custom middleware that only invokes it for your specified routes. So Instead of:
app.use(passport.session());
you could:
app.use(function(req, res, next){
if(req.url.match('api/image'))
next(); // do not invoke passport
else
passport.session()(req, res, next)
// same as doing == app.use(passport.session())
});
Solution 2:
If you use passport.session()
middleware, deserialize will happen for every route:
https://github.com/jaredhanson/passport/blob/33075756a626999c6e2efc872b055e45ae434053/lib/strategies/session.js#L53-L69
The solution would be to add it only to ones which use passport.
Post a Comment for "Expressjs Passportjs De-serializes User Object For Every Request To A Route"