0
I’m trying to input into the database the contents of the variables: token and now. The respective fields in the table users of the bank are: passwordResetToken and passwordResetExpires.
I can return the value of the variables in the console: token and now.
I am trying to save this data in the tables: passwordResetToken and passwordResetExpires.
Making the logic using the Sequelize ORM:
exports.forgotPassword = async (req, res) => {
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const { email } = req.body;
try {
const user = await User.findOne({ where: {email} }); //users table
const token = crypto.randomBytes(20).toString('hex');
const now = new Date();
now.setHours(now.getHours() + 1); //1 HR valid token
//error sequelize save datas in db
await User.findByPk( user.id, { //error-findByIdAndUpdate--mongo method - users table { where: {email} }
'$set': {
passwordResetToken: token,
passwordResetExpires: now,
}
});
const msg = {
to: email,
from: '[email protected]', // '[email protected]'
subject: 'Sending with Twilio SendGrid is Fun',
text: 'and easy to do anywhere, even with Node.js',
html: token, email, //'<strong>and easy to do anywhere fd, even with Node.js {token} </strong> {token}',
};
sgMail.send(msg);
console.log(sgMail);
console.log(token);
console.log(now);
res.status(200).json({
Success: "Request sent successfully,check token in your email!"
});
} catch (err) {
res.status(400).send({ error: 'E-mail does not exist!' });
}
}
Every process is done, but does not save the values of token and now in the fields passwordResetToken and passwordResetExpires on the table users bank. The probable error is here:
//error sequelize save datas in db
await User.findByPk( user.id, { //error-findByIdAndUpdate--mongo method - users table { where: {email} }
'$set': {
passwordResetToken: token,
passwordResetExpires: now,
}
});
I have no error of reply in the console, however the two fields of the table users are not saved/update. On line 114, this one $set came the way it was done with the mongodb,and functioned normal,now migrating to mysql sequelize,I’m trying to get the data into the database, but still unsuccessful.
Any suggestions?
Thank you all in advance! Thank you!
Please edit your question by clicking on "[Edit]" to exchange image codes for text. How you can read here, image code is not a good idea.
– Luiz Felipe
Done! Could you give me a light for kindness?
– Guillerbr