I am currently trying to look up users by email in Angular and Meteor and on my client side code I am using Accounts.findUserByEmail()
.
On the client I am calling it with Meteor.call()
asynchronously. The problem is I can only console.log() or alert() a value back but I can't for example return true
or return false
. It's not read by my client?
Here is a preview of my server side method:
checkUserByEmail : function (email) {
this.unblock();
check(email, Match.Any);
console.log('Checking to see if ', email, 'is registered')
var userEmail = Accounts.findUserByEmail(email);
if(userEmail){
console.log(userEmail + ' Email account is registered')
return true
}
else{
console.log(userEmail + ' Email account is not registered' )
return false
}
return userEmail;
}
Then somewhere on my client:
$scope.doesUserEmailExist = function(judge){
Meteor.call('checkUserByEmail', judge.email , function(err, res){
if(res){
console.log(judge.email + ' exists as a registered email!');
alert('Judge is Valid')
return true;
}
else if(err){
console.log('Error ',judge.email , 'does not exist!');
return false;
}
})
}
I am using $scope.doesUserEmailExist to see if a user is registered to my app by entering an email in the input form. When I enter a valid email address I get a console.log value but I can't read any return
values?
I was hoping that I could use $scope.doesUserEmailExist(email) === true
but I haven't had a successful run at it.