vincenius
6/20/2018 - 6:27 AM

Node Passport State

Node Passport State

app.get('/auth/facebook/menu', function(req,res,next) {
  // url parameter ?state=subpage is passed to login
  // this can be used for routing after callback
	let param = req.query.state;
	passport.authenticate('facebook', { state: param })(req,res,next);
});

app.get('/auth/facebook/callback', passport.authenticate(
  'facebook', 
  { failureRedirect: '/' }), 
  function(req, res) {
	let state = req.query.state;
	// redirect user depending from
	// where he came from
	switch(state) {
          case 'subpage':
              res.redirect('/subpage');
              break;
          default:
              res.redirect('/');
      }
});