我在用火车头,试图用护照。尽管如此,我还是弄明白了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)谢谢你的帮助
发布于 2013-06-28 08:06:25
据我所知,您首先需要使用github page中列出的passport.use向passport注册本地策略。
发布于 2014-01-29 00:42:11
您将需要使用:
passport.use(new LocalStrategy(function(username, password, done) {
...
}));来注册策略。如果您将其放入pass.js这样的文件中,则需要将其包含在启动文件中:
var pass = require('./pass');当我忘记将它包含在我的app.js文件中时,我遇到了同样的问题。虽然你不会在你的启动文件中显式地调用'pass‘,但passport会在初始化时使用它。
发布于 2013-11-17 04:00:19
确保在本地库中安装了本地策略。Npm安装passport-local
https://stackoverflow.com/questions/17354704
复制相似问题