在 MEAN.js 中通过护照登录后重定向到另一个页面而不是索引

redirect to another page rather than index after sign in via passport in MEAN.js

我正在使用 MEAN.js 创建一个 CRUD 网络应用程序。 在此应用程序中,我使用护照进行身份验证

登录后重定向到首页 但是我怎样才能像我的模块页面一样重定向到另一个页面呢?

干杯!

您需要使用 authenticate(http://passportjs.org/docs/authenticate)

将其用作路由处理程序

app.post('/login', passport.authenticate('facebook', function(error, user, info){
  if (error) {
    log.error(error);
    next(error);
  } else {
    if (user) {
      // do the redirect here
    } else {
      next(new Error("Invalid Request"));
    }
  }
}));

或者作为中间件

app.post('/login',
  passport.authenticate('facebook'),
  function(req, res) {
    // do redirect here
  });

或使用选项

app.post('/login',
  passport.authenticate('facebook', { successRedirect: '/user',
                               failureRedirect: '/login' }));