gpt4 book ai didi

mysql - Express js 抛出 Rethrow 非 MySQL 错误

转载 作者:行者123 更新时间:2023-11-28 23:12:04 26 4
gpt4 key购买 nike

您好,我正在学习 express 和 passport,我试着做一个注册表单,当我尝试使用 MySQL 插入一行时,我收到了这个错误,但我的表正在正确更新。

passport.use(
'local-signup',
new LocalStrategy({
usernameField : 'email',
passwordField : 'password',
passReqToCallback : true // allows us to pass back the entire request to the callback
},
function(req, email, password, first_name, done) {
var displayName = req.body.first_name;
// find a user whose email is the same as the forms email
// we are checking to see if the user trying to login already exists
dbConnection.query("SELECT * FROM users WHERE email = ?",[email], function(err, rows) {
if (err) {
return done(err);
}
if (rows.length) {
return done(null, false, { error: 'That email is already being used.' });
} else {
// if there is no user with that email
// create the user
var salt = bcrypt.genSaltSync(10);
var passwordHash = bcrypt.hashSync(password, salt);

var userInfo = {
email: email,
first_name: displayName
};

var insertQuery = "INSERT INTO users ( email, password, first_name) values ('"+email+"','"+passwordHash+"','"+displayName+"')";
console.log(insertQuery);
dbConnection.query(insertQuery,function(err, rows) {
userInfo.id = rows.insertId;
console.log(rows);
return done(null, userInfo);
});
}
});
})
);

Error of the code in console

最佳答案

删除函数中不需要的 first_name 参数。

function(req, email, password, first_name, done)

'代替'

function(req, email, password, done)

关于mysql - Express js 抛出 Rethrow 非 MySQL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45550535/

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