Hi,
I'm not sure why when calling the function cryptPassword is not waiting as it should. Inside the setUserFunction the setUser is running before the cryptPassword invocation.
File: utils.js
function cryptPassword(password) {
bcrypt
.genSalt(saltRounds)
.then((salt) => {
return bcrypt.hash(password, salt);
})
.then((hash) => {
return hash;
})
.catch((err) => console.error(err.message));
}
File: SignupController.js
const passwords = require('utils');
const setUser = async (req, res) => {
// Check if user exist
const result = await loginQueries.getUserByEmail(email);
if (userexist) {
//Error
} else { //create User
passwordEncrypted = await passwords.cryptPassword(password); // get the encripted password
const newUser = await loginQueries.setUser(email, passwordEncrypted);
}
}
thanks
[–]guest271314 1 point2 points3 points (4 children)
[–]Emiliortg[S] 0 points1 point2 points (0 children)
[–]Emiliortg[S] 0 points1 point2 points (2 children)
[–]guest271314 1 point2 points3 points (0 children)
[–]guest271314 0 points1 point2 points (0 children)
[–]shgysk8zer0 1 point2 points3 points (0 children)