One of the challenges I'm facing in my app involves checking for registered users. Specifically, when a user is typing their email address to log in, I want to verify if they exist with each keystroke and provide feedback accordingly.
Here is the code I have implemented:
Template.login.events({
'keyup .userEmail': function(event){
event.preventDefault();
var email=$('[name=email]').val();
var checkExistence=Meteor.users.find({ emails: { $elemMatch: { address: email } }}).count() > 0 ;
console.log(checkExistence);
}
});
The expectation is that the query should return true if the email address already exists in the system.
However, even when a user has entered their complete email address like [email protected] (which is present in the database), the value of checkExistence
remains false instead of true.
This discrepancy raises the question, why is this happening and how can I accurately determine if the user's email is already registered in the system?