2013-06-27 28 views
0

我正在使用機車,試圖使用護照。作爲各種指南,我仍然對自己的需求函數感到滿意,對於我需要的東西運行並不是特別清楚。以下是我的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) 

感謝所有幫助

回答

1

按照護照使用passport.use註冊本地策略,如github page列出。

+0

embrrassed這是我的問題... :) –

0

確保您在當地圖書館安裝了本地策略。 NPM安裝護照本地

1

您將需要使用:

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

註冊的策略。如果你把這個文件一樣pass.js,你需要把它列入你的啓動文件:

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

我遇到同樣的問題時,我忘了把它列入我app.js文件。雖然您不會在啓動文件中明確地調用「pass」,但護照在初始化時會使用它。