我正在尝试将注册详细信息添加到数据库。如果通过此方法我仅添加用户名和密码,那么我可以在mongo db中插入,但是我尝试插入名称,将所有内容通过电子邮件发送,然后他们给出MissingUsernameError
。
{
firstName: 'Name',
lastName: 'Last',
email: 'abc@gmail.com',
phone: '1111111111',
password: 'password'
}
{ MissingUsernameError:未提供用户名 然后在Promise.resolve。然后(C:\ Users \ Music \ web \ node_modules \ passport-local-mongoose \ index.js:231:17) 在process._tickCallback(内部/进程/next_tick.js:68:7)处名称: 'MissingUsernameError',消息:'未提供用户名'}
app.post("/register", function(req, res) {
console.log(req.body);
var newUser = new User({
firstName: req.body.firstName,
lastName: req.body.lastName,
email: req.body.email,
phone: req.body.phone
});
User.register(newUser, req.body.password, function(err, user) {
if (err) {
console.log(err);
return res.render("register");
}
passport.authenticate("local")(req, res, function() {
res.redirect("/");
});
});
});