Comparing the password on user login request. Used async and await to wait till get the actual response.
I expect it to run on following order 1,2,3,4 (order of console.log)
but it executes as 1, 3, 4, 2. Please help.
script does not wait for comparePassword
async login(request){
let response = await User.findOne({ email: request.email }, async (err, user) => {
if (err) throw err;
console.log('1');
let isMatch = await user.comparePassword(request.password, (err, isMatch) => {
console.log('2');
if (err) throw err;
request.isMatch = isMatch;
});
console.log('3');
return request;
});
console.log('4');
console.log('response', response);
}