Meteor unable to access callback response param

37 Views Asked by At

Meteor 1.3 with mdg:validated-method

imports/api/user/methods.js

export const register = new ValidatedMethod({

    name: 'register',

    validate: new SimpleSchema({
        mobile: { type: String },
    }).validator(),

    run({ mobile }) {
        let response = {
            success: false,
            message: 'Error'
        };

        if(true) {
            response.success = true;
            response.message: 'Done';
        }

        return response;
    }
});

imports/ui/pages/home.js

UserMethods.register.call({mobile}, (error, response) => {
    console.log(error); // okay
    console.log(response); // unable to access response

    if(response.success) {
        template.$('#enter-mobile').hide();
        template.$('#enter-otp').fadeIn();
    }
});

I'm unable to access response in UserMethods.register.call({mobile}, (error, response)

How to fix this?

1

There are 1 best solutions below

0
atulmy On

So for anyone who is facing same problem, the issue was I did not load the imports/api/user/methods.js on server!

/app/imports/startup/server/api.js import '../../api/user/methods';

The callback response essentially comes from the server.