New to using Meteor, I am trying to create a registration form with Meteor. I am facing some challenges with the `findOne` and `subscribe/publish` functions. Here is my `collection.js` file:
User_Customer = new Meteor.Collection("USER_CUSTOMER");
Customer = new Meteor.Collection("CUSTOMER");
This is my `publish.js` file in the `/server` directory:
Meteor.publish("CUSTOMER", function() {
return Customer.find();
});
Meteor.publish("USER_CUSTOMER", function() {
return User_Customer.find();
});
And here is the function I have created to subscribe and find items in the `/client` directory:
function isAvailableForUserRegister(email, identity, phone){
Meteor.subscribe("CUSTOMER", function(){
var cust = null;
cust = Customer.findOne({Identity: identity});
if(cust != null){
Meteor.subscribe("USER_CUSTOMER", function(){
var uc1 = null;
uc1 = User_Customer.findOne({Email: email});
if(uc1 != null){
var uc2 = null;
uc2 = User_Customer.findOne({Phone: phone});
if(uc2 != null)
return true
else
return false;
}else return false;
});
}else return false;
});
}
The `isAvailableForUserRegister` function checks if an email, identity, or phone number already exist in the collections:
Identity in Customer
Email in User_Customer
Phone in User_Customer
The issue I am facing is that the process does not continue to enter the second subscription, as the `cust` variable has an `undefined` value. I have tried debugging with Chrome, but still unable to find a solution. Can anyone help me resolve this function?
Thank you.