护照注册 – 本地返回“缺less凭证”

试图使用快递设置节点和护照,我偶然发现了一个问题,我有一些debugging问题。

有一个非常基本的registry单,它一直工作到按下注册button。 但是,注册不起作用。 没有错误消息,但是代码确实注意到注册失败(没有错误,但没有用户)。 经过一段时间后,我设法得到了这个passport.authenticate(注册本地发送一条消息说,“失踪证书”信息,但我永远不知道什么凭证或为什么。

我在post上使用的返回码是:

app.post('/signup', function(req, res, next) { passport.authenticate('local-signup', function(err, user, info) { if (err) { return next(err); // will generate a 500 error } // Generate a JSON response reflecting authentication status if (! user) { console.log('Got the following back'); console.log('Error: ' + err); console.log('User: ' + user); info = JSON.stringify(info); console.log('Info: '+ info); for(var key in info) { console.log(key); } return res.send({ success : false, message : 'authentication failed'}); } return res.send({ success : true, message : 'authentication succeeded' }); })(req, res, next); }); 

而回报是:

 GET /signup 304 24.943 ms - - Got the following back Error: null User: false Info: {"message":"Missing credentials"} 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 POST /signup 200 6.933 ms - 51 

我想看看这个post收到了什么,但不知道如何以一个简单的方式得到这个:)

好吧,所以经过一番讨论,我发现问题在哪里。

你将需要加载urlencodedParser。 所以在路线的开始添加了以下内容

 var bodyParser = require('body-parser'); module.exports = function(app, passport) { var urlencodedParser = bodyParser.urlencoded({ extended: false }) 

一旦完成,你所要做的就是通过urlencodedParser和Bobs你的叔叔传递呼叫

  app.post('/signup', urlencodedParser, function(req, res, next) { passport.authenticate('local-signup', function(err, user, info) { if (err) { return next(err); // will generate a 500 error } // Generate a JSON response reflecting authentication status if (! user) { console.log('Got the following back'); console.log('Error: ' + err); console.log('User: ' + user); info = JSON.stringify(info); console.log('Info: '+ info); for(var key in info) { console.log(key); } var userd = JSON.stringify(req.body); console.log('Request : ' + userd); return res.send({ success : false, message : 'authentication failed'}); } return res.send({ success : true, message : 'authentication succeeded' }); })(req, res, next); });