I'm encountering an issue where I am using a variable within a nested function. After assigning a value to it, I pass it to the parent function. However, when I call the function, nothing is displayed.
function checkUserExists(identifier) {
let user = false;
UsersModel.findOne({ email: identifier }, function (error, foundUser) {
if (!error && foundUser) user = foundUser;
else {
console.log("error or user not found: " + error);
}
});
return user;
}