Skip to content
Advertisement

Gettting an undefined value from bcrypt hash function

Ok, I’m getting an undefined value from a function, I don’t know why, I’m trying to get the value of a password hash for insert in the database, but the const that have the function has the value “undefined”, so what I should change in my code?

JavaScript

Advertisement

Answer

When you call bcrypt.hash() and pass in a callback function, no Promise is returned. You can leave off that callback and then your await will work as you expect.

Basically, as is common with a lot of APIs, you can choose between the “old school” callback function approach or the more modern Promise/async model. One or the other, but not both at the same time.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement