且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将本地护照与 restify 集成时遇到问题

更新时间:2023-02-08 12:01:54

此护照文档页面显示,在底部的自定义回调"部分中,对于您在主代码段中使用通行证的方式,请求方法应该是get",而不是post".我从该页面复制代码片段:

This passport documentation page shows, in the "Custom Callback" section at the bottom, that, for the way you are using passport in your main snippet, the request method should be a 'get', not a 'post'. I copy here the code snippet from that page:

app.get('/login', function(req, res, next) {
  passport.authenticate('local', function(err, user, info) {
    if (err) { return next(err); }
    if (!user) { return res.redirect('/login'); }
    req.logIn(user, function(err) {
      if (err) { return next(err); }
      return res.redirect('/users/' + user.username);
    });
  })(req, res, next);
});

该页面还有其他关于如何使用护照的示例,包括您尝试的本地"变体.

That page has other examples of how passport can be used, including the "local" variant that you attempted.