I am writing simple app using node.js and passport.js for auth.
Can I get access to the request object in serializeUser?
Passport uses serializeUser function to persist user data (after successful authentication) into session. Function deserializeUser is used to retrieve user data from session.
isAuthenticated()” function to protect logged in routes. Passport JS conveniently provides a “req.isAuthenticated()” function, that. returns “true” in case an authenticated user is present in “req.session.passport.user”, or. returns “false” in case no authenticated user is present in “req. session.
Passport's middleware is built in a way that allows you to use multiple strategies in one passport.
This is possible with the help of done() function. It is an internal passport js function that takes care of supplying user credentials after user is authenticated successfully. This function attaches the email id to the request object so that it is available on the callback url as "req. user".
It's actually pretty simple: req
is added as the first parameter
passport.deserializeUser(function(req, id, done) {...
https://github.com/jaredhanson/passport/issues/111
If you do req.res.render('whatever'
it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With