gpt4 book ai didi

javascript - Passport 扔 "undefined is not a function"

转载 作者:搜寻专家 更新时间:2023-10-31 23:42:57 26 4
gpt4 key购买 nike

这是我第一次使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com