mosh-hamedani / vidly-api-node

309 stars 285 forks source link

Authentication & Authorization section: "error: undefined No callback function was given." #28

Closed veronicapc92 closed 4 years ago

veronicapc92 commented 4 years ago

Hi everyone,

When trying to send a post request to http://localhost:3900/api/users I get the following error: "undefined No callback function was given."

Anyone knows how to solve it?

@mosh-hamedani

Many thanks

veronicapc92 commented 4 years ago

The problem was coming from bcrypt. Bcrypt-nodejs is now deprecated so I installed bcryptjs instead.

Then I went to vidly-api-node/routes/users and replaced this code:

const salt = await bcrypt.genSalt(10); user.password = await bcrypt.hash(user.password, salt, null); await user.save();

with this code:

const saltRounds = 10; bcrypt.hash(user.password, saltRounds, async function(err, hash) { if (err) throw err; user.password = hash; await user.save(); });

Not sure the code is 100% correct but it seems to work. I'll close this issue now.