[FIXED] Meteor Method return value not reflecting on cliend side

I have written a Meteor.call() method to check if the user already exisits in the system.

Below is the code

views/clientside.js

  let inviteEmailAddress = FlowRouter.getParam("inviteEmail");
    var emailExist = false;
    if (inviteEmailAddress !== "") {
       Meteor.apply("v1/checkIfEmailExists", { inviteEmailAddress },  { wait :true  }, (e, r ) => {
        if (e) {
          Meteor.Error(404, "Error checking the email ");
        } else {
          if (r) {
            console.log(inviteEmailAddress + " result found ", r);
            emailExist = true;
          } else {
            console.log(inviteEmailAddress + " result not found ", r);
          }
        }
      });

imports/api/methods.js

export const checkIfEmailExists = new ValidatedMethod({
    name: 'v1/checkIfEmailExists',
    validate: new SimpleSchema({
        inviteEmailAddress: { type: String },
    }).validator(),
    run({ inviteEmailAddress }) {
        console.log("received ", inviteEmailAddress ) ; 
       console.log(Accounts.findUserByEmail(inviteEmailAddress)) ;

        return Meteor.isServer && Accounts.findUserByEmail(inviteEmailAddress)
        // return Meteor.users.find({ _id: { $in: users } }, { fields: { profile: 1, info: 1, emails: 1 } }).fetch();
    },
});

My issue is client is rendering always false even though the user is available in the database. So essentially the return value is not at all reflecting on the clientside data.

Any help would be great.

Turn your emailExist variable into a reactive var.
https://atmospherejs.com/meteor/reactive-var

1 Like

Thanks Story Teller. You are a saviour here :blush: Now Its working great.

1 Like