我是护照(和一般节点)的新手,并且一直在使用本教程(http://mherman.org/blog/2015/01/31/local-authentication-with-passport-and-express-4/#.VczPbTBViko)将护照身份验证添加到更大的Web应用程序中。我想我一直在正确地处理事情,但是当我在终端中启动应用程序时,我收到以下错误。
passport.use(new LocalStrategy(Admin.authenticate()));
^
TypeError: undefined is not a function
at Object.<anonymous> (/Users/goldru/design-data/app.js:37:38)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/goldru/design-data/bin/www:7:11)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
我检查了package.json,似乎安装了所有相关的库。
以下是相关代码。
来自app.js的:
//connect to db; require models
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/design-data-test');
var Test = require('./models/Tests');
var Question = require('./models/Question');
var User = require('./models/User');
var Option = require('./models/Option');
var Admin = require('./models/Admin');
//require passport
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var routes = require('./routes/index');
var express = require('express');
var app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//passport setup
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
//config admin
var Admin = require('./models/Admin');
passport.use(new LocalStrategy(Admin.authenticate()));
passport.serializeUser(Admin.serializeUser());
passport.deserializeUser(Admin.deserializeUser());
admin.js:
var mongoose = require('mongoose');
var passportLocalMongoose = require('passport-local-mongoose')
var AdminSchema = new mongoose.Schema({
username: String,
password: String
});
AdminSchema.plugin(passportLocalMongoose);
module.export = mongoose.model('Admin', AdminSchema);
答案 0 :(得分:2)
这是一个错字。您必须在admin.js中使用module.exports
而不是module.export
。