Bcrypt password comparison doesn't work. Even user.password is empty in Node.js Express App Bcrypt password comparison doesn't work. Even user.password is empty in Node.js Express App mongoose mongoose

Bcrypt password comparison doesn't work. Even user.password is empty in Node.js Express App


There is nothing wrong with your code. I have tested it on my side here. The only anomaly I am looking at is while sending the response you are having an Array of Responses but reading it as a single object.

Here is what the above jargon I said means

INSTEAD OF

User.find({incomingEmail}).then((user) => {    res.send(user.password);}).catch(() => {    res.status(404).json({status: 404, data: 'Email not matched'});});

Do this

User.find({incomingEmail}).then((user) => {        res.send(user[0].password);    }).catch(() => {        res.status(404).json({status: 404, data: 'Email not matched'});});

OR IN ANOTHER CASE

what I can see you can do is to instead of using MONGOOSE ONLY FIND method ! you can go with FINDONE method too so that it would have no need to read out an array of JSON responses for a single user. FINDONE will help you with the code you already have.