I have this function which saves user in database:
exports.saveUser = ({ first_name, last_name, email, password }) => {
const query = "insert into users (first_name, last_name, email, password_hash) values ($1, $2, $3, $4) RETURNING *";
bcrypt.hash(password, 10, async function (err, hash) {
const res = await db.query(query, [first_name, last_name, email, hash]);
return res.rows[0];
});
return res;
};
I have async function inside bcrypt callback where insertion is happening and where I'm returning inserted row. How do i make it to return for saveUser function?
So at the end saveUser()
will be that res.rows[0]
record?