I'm trying to encrypt the password of my customer controller using bcryptjs, but it ends up being sent as null to "password" in the database. I came to suspect that the problem would be in bcryptjs, but after giving a console.log in "hashedPassword" I could see that the password is indeed being encrypted, but for some reason my database recognizes it as "null"
const db = require('../../models/index');
const bcrypt = require('bcryptjs');
exports.store = async (req, res) => {
const {name, email, password, country, city, state, address, postalCode} = req.body;
try {
const customerAlreadyExists = await db.Customer.findOne({ where: { email } });
const hashedPassword = bcrypt.hash(password, 10);
if (customerAlreadyExists) {
res.status(400).json('Customer already exists.');
}
const createdCustomer = await db.Customer.create({
name,
email,
hashedPassword,
country,
city,
state,
address,
postalCode
});
return res.status(200).json(createdCustomer);
} catch (err) {
console.log(err);
}
}