Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing request object in serializeUser function in passport.js

I am writing simple app using node.js and passport.js for auth.

Can I get access to the request object in serializeUser?

like image 992
Yurij Avatar asked May 11 '13 16:05

Yurij


People also ask

What is serializeUser and deserializeUser in passport?

Passport uses serializeUser function to persist user data (after successful authentication) into session. Function deserializeUser is used to retrieve user data from session.

What is req isAuthenticated ()?

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.

Can passport use multiple strategies?

Passport's middleware is built in a way that allows you to use multiple strategies in one passport.

What is done function in passport js?

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".


1 Answers

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.

like image 83
laggingreflex Avatar answered Oct 14 '22 08:10

laggingreflex