0

我正在使用机车,试图使用护照。我仍然对 require 函数有所了解,因为各种指南并不是特别清楚我需要什么才能使事情运行。以下是我的 routes.js:

// MVC routes can be mapped mapped to controllers using convenient
// `controller#action` shorthand.  Standard middleware in the form of
// `function(req, res, next)` is also fully supported.  Consult the Locomotive
// Guide on [routing](http://locomotivejs.org/guide/routing.html) for additional
// information.
//
passport = require('/usr/local/lib/node_modules/passport');
passport_local = require('/usr/local/lib/node_modules/passport-local');

module.exports = function routes() {
this.root('pages#main');
this.match('login', passport.authenticate('local', { successRedirect: '/',
                                                     failureRedirect: '/login' }))
}

它会出现以下错误消息:

Express
500 Error: no strategy registered under name: local

    at attempt (/usr/local/lib/node_modules/passport/lib/passport/middleware/authenticate.js:237:37)
    at Passport.authenticate (/usr/local/lib/node_modules/passport/lib/passport/middleware/authenticate.js:244:7)
    at callbacks (/usr/local/lib/node_modules/locomotive/node_modules/express/lib/router/index.js:161:37)
    at param (/usr/local/lib/node_modules/locomotive/node_modules/express/lib/router/index.js:135:11)
    at pass (/usr/local/lib/node_modules/locomotive/node_modules/express/lib/router/index.js:142:5)
    at Router._dispatch (/usr/local/lib/node_modules/locomotive/node_modules/express/lib/router/index.js:170:5)
    at Object.router (/usr/local/lib/node_modules/locomotive/node_modules/express/lib/router/index.js:33:10)
    at next (/usr/local/lib/node_modules/locomotive/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.methodOverride [as handle] (/home/matt/node/hello/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:37:5)
    at next (/usr/local/lib/node_modules/locomotive/node_modules/express/node_modules/connect/lib/proto.js:190:15)

谢谢你的帮助

4

3 回答 3

1

据我所知,您首先需要使用护照注册本地策略passport.use,如github 页面上所述。

于 2013-06-28T00:06:24.833 回答
1

您将需要使用:

passport.use(new LocalStrategy(function(username, password, done) {
 ...
}));

注册策略。如果你把它放在一个类似的文件中pass.js,你需要将它包含在你的启动文件中:

var pass = require('./pass');

当我忘记将它包含在我的app.js文件中时,我遇到了同样的问题。尽管您不会在启动文件中显式调用“pass”,但在初始化时将使用它。

于 2014-01-28T16:42:10.820 回答
0

确保在本地库中安装了本地策略。Npm 安装本地护照

于 2013-11-16T20:00:19.377 回答