当使用护照本地与Sailsjs没有反应

我试图通过sailsjs实现护照本地化,并且在尝试进行身份validation时没有得到任何响应。 这里是代码:

//config/passport.js var passport = require('passport') , LocalStrategy = require('passport-local').Strategy; module.exports = { express: { customMiddleware: function(app){ console.log('Express midleware for passport'); app.use(passport.initialize()); app.use(passport.session()); } } }; passport.serializeUser(function(user, done) { done(null, {omar: "omar"}); }); passport.deserializeUser(function(id, done) { done(null, {omar: "omar"}); }); passport.use(new LocalStrategy( function(username, password, done) { // asynchronous verification, for effect... process.nextTick(function () { return done(null, {user: "omar"}); }); } )); 

_

 //LoginController.js var passport = require('passport'); var loginController = { login: function(req, res){ //res.json(req.param('username')); console.log('loginctrl'); passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }), function(req, res) { console.log('passport auth'); res.send("success"); } }, /** * Overrides for the settings in `config/controllers.js` * (specific to LoginController) */ _config: {} }; module.exports = loginController; 

我试图POST /login,但唯一的控制台消息是:

快递midleware护照
loginctrl

意思这不是调用LocalStrategycallback,我得到“0没有响应”错误..
这是为什么?

Solutions Collecting From Web of "当使用护照本地与Sailsjs没有反应"

您在这里调用passport.authenticate的方式有问题:

 passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }), function(req, res) { console.log('passport auth'); res.send("success"); } 

passport.authenticate返回一个应该在请求/响应中调用的函数。

看到这里的一些帆/护照集成的例子: