Express / Angular,在Passport身份验证后不重定向

时间:2014-09-25 18:47:57

标签: angularjs node.js express passport.js meetup

在Express I中使用:

var router = express.Router();
router.get('/auth/*', function (req, res, next) {
  next();
})
app.use(router);

app.all('/*', function(req, res) {
  res.sendfile('index.html', { root: __dirname + '/app/dist' });
});

在Angular $ routeProvider中:

when('/auth/:type', {}).

当我使用社交登录Meetup /auth/meetup时,它会进行身份验证,但不会按照successRedirect Passport中的指定重新路由到/profile/meetup

app.get('/auth/meetup', passport.authenticate('meetup', { scope : 'email' }));

app.get('/auth/meetup/callback',
    passport.authenticate('meetup', {
        successRedirect : '/profile/meetup',
        failureRedirect : '/login'
    }));

当我点击带有href="/auth/meetup"的按钮时,我在地址栏中显示一个空白屏幕,其中包含地址栏中的网址:http://localhost:2997/auth/meetup当我刷新页面时,我会自动路由到'/profile/meetup'所以身份验证成功。

为什么认证后Node / Express / Angular没有重定向到/ profile / meetup?

1 个答案:

答案 0 :(得分:1)

您不希望angularjs将HTML5风格的单页应用程序路径作为路径处理。您希望浏览器为/auth/meetup执行整页加载。因此,在您的HTML <a>标记中添加target="_self",这将禁用角度路由器并允许传统的超链接工作。

相关问题