护照投掷“未定义不是一个功能”

时间:2014-05-25 00:57:21

标签: javascript node.js mongoose passport.js passport-local

这是我第一次使用护照。

我在尝试启动应用时遇到此错误:

passport.use(new LocalStrategy(Account.authenticate()));
             ^
TypeError: undefined is not a function
    at Object.<anonymous> (/Users/drewwyatt/Sites/JS/Node/MWInternal/app.js:38:14)

以下是app.js

的(相关)部分
var express = require('express');
var user = require('./routes/user');
var http = require('http');
var path = require('path');
var mongoose = require('mongoose');
var passport = require('passport');
var LocalStrategy = require('passport-local').LocalStrategy;

var app = express();
var connectionString = '***************';


// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(require('less-middleware')(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

// passport config
var Account = require('./models/account');
passport.use(new LocalStrategy(Account.authenticate()));
passport.serializeUser(Account.serializeUser());
passport.deserializeUser(Account.deserializeUser());

mongoose.connect(connectionString);

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

...

/models/account.js

var mongoose = require('mongoose'),
    Schema = mongoose.Schema
    passportLocalMongoose = require('passport-local-mongoose');

var Account = new Schema({
    email: String,
    password: String
});

Account.plugin(passportLocalMongoose);

module.exports = mongoose.model('Account', Account);

我错过了什么?

1 个答案:

答案 0 :(得分:4)

更改

var LocalStrategy = require('passport-local').LocalStrategy;

var LocalStrategy = require('passport-local').Strategy;

passport-local模块exports Strategy

var Strategy = require('./strategy');
exports.Strategy = Strategy;