我必须进行建模,并且都需要在我的网站上进行身份验证。一个工作正常,而另一个在签署表单时显示错误的请求错误。 另外,我如何在单个数据库中创建两个集合:
passportLocalMongoose被声明,但从不读取其值。
const Worker = require("./models/worker"),
passport = require("passport"),
LocalStrategy = require("passport-local"),
passportLocalMongoose = require("passport-local-mongoose");
mongoose.connect("mongodb://localhost/worker");
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(require("express-session")({ //require inline exp session
secret: "rich forever",
resave: false, // required
saveUninitialized: false //required
}));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(Worker.authenticate()));
passport.serializeUser(Worker.serializeUser());
passport.deserializeUser(Worker.deserializeUser());
我的worker.js看起来像这样:
var mongoose = require("mongoose"),
passportLocalMongoose = require("passport-local-mongoose");
var workerSchema = new mongoose.Schema({
username: String,
password: String
});
workerSchema.plugin(passportLocalMongoose);
module.exports = mongoose.model("Worker", workerSchema);