作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
这是我第一次使用 Passport 。
当我尝试启动我的应用程序时,我不断收到此错误:
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);
我错过了什么?
最佳答案
改变
var LocalStrategy = require('passport-local').LocalStrategy;
到
var LocalStrategy = require('passport-local').Strategy;
passport-local
模块 exports 策略
:
var Strategy = require('./strategy');
exports.Strategy = Strategy;
关于javascript - Passport 扔 "undefined is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23851062/
我是一名优秀的程序员,十分优秀!