I am trying to compare the password of user and their password in the DB where it is saved (MongoDB). When that user logs in, their input password and DB password need to be compared. But when I run the code it's showing me an error of Error: data and hash arguments required.
var db=require('../config/connection')
var collection=require('../config/collections')
const bcrypt=require('bcrypt')
module.exports={
doSignup:(userData)=>{
return new Promise(async(resolve,reject)=>{
userData.Password= await bcrypt.hash(userData.Password,10)
db.get().collection('user').insertOne(userData).then((data)=>{
resolve(data.insertedId)
})
})
},
doLogin:(userData)=>{
return new Promise(async(resolve,reject)=>{
let loginstatus=false
let response={}
let user=await db.get().collection(collection.USER_COLLECTION).findOne({Email:userData.Email})
if(user){
bcrypt.compare(userData.Password,user.Password).then((status)=>{
if(result){
console.log("login success");
}else{
console.log("login failed");
}
})
}else
{
console.log('login failed');
}
})
}
}