{option: value},{option: value}
Или
{option: value,option: value}
async function sendUser(url,name,email,role,password) {
this.url = url
this.name = name
this.email = email
this.role = role
this.password = password
this.options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body:
JSON.stringify({
name: this.name,
email: this.email,
role: this.role,
password: this.password
})
}
const response = await fetch(this.url,this.options)
const data = await response.json()
if(data) {
alert('ok')
}
else {
alert('null')
}
}
//Клик на кнопку
const user = {
name: $('#firstname').val(),
email: $('#email').val(),
role: $('#role').val(),
password: $('#password').val()
}
sendUser('/register-step2',user.name,user.email,user.role,user.password)
app.post('/register-step2', (req,res,next) => {
let email = req.body.email;
let role = req.body.role;
let firstname = req.body.firstname;
let password = req.body.password;
let select = `SELECT * FROM users WHERE email = '${email}'`;
let insert = `INSERT INTO users (firstname, email, hash, role) VALUES('${firstname}' ,'${email}', '${password}', '${role}')`
connection.query(select, (err,res) => {
if (res.length < 1) {
bcrypt.genSalt(saltRounds, (err, salt) => {
bcrypt.hash(password, salt, (err, hash) => {
connection.query(insert, (err,res) => {
if(err) console.log(err);
else {
console.log(email)
}
})
})
})
}
else {
return console.log('user registered!');
}
})
// const insertToUsers = new Query(`INSERT INTO`,`users`,`firstname,email,password,role`,`'${firstname}','${email}','${password}','${role}'`)
// insertToUsers.send()
return res.redirect('/step2')
});