How to redirect user to home page with his ID after authentication using Node.js and Passport? -
i have started learning node.js go easy on me :p
i'm using passport autenticate user. user needs redirected home page id url parameter after successful authentication, example:
/home?id=325346546
here part of routes.js
// process login form app.post('/', passport.authenticate('local-login', { successredirect : '/home?id='+req.user._id, //error because 'req' isn't declared failureredirect : '/', failureflash : true }));
this idea, want pass id parameter url.
i have tried putting a
function(req, res) { }
but didn't work. appreciated.
thanks ben got working, anwser own question here complete code:
// process login form app.post('/', function(req, res, next) { passport.authenticate('local-login', {failureflash:true}, function(err, user, info) { if (err) { return next(err); } if (!user) { return res.redirect('/'); } req.login(user, function(err) { if (err) { return next(err); } return res.redirect('/home?id=' + user._id); }); })(req, res, next); });
Comments
Post a Comment