No result from call to login

I have a Angular1 Meteor project.
In one component called login (login.js), I need to pass username and password to a meteor method on clinet side loginUser (in user.js on client). All I need is create a wrapper method for Meteor.loginWithPassword.

So in my login.html , I have login

right now the code is within constructor under helpers:
like
loginUser: function () {
// …
console.log(“inside login”);
Meteor.call(‘loginUser’, ‘myusername’,‘mypassword’);
}

and in user.js
Meteor.methods({
loginUser() {

  Meteor.loginWithPassword(username,password, function(err) {
    if(err)
    console.log("could not login " + err.message);
  else
    console.log("success");
  });
}) 

I get the error ’ could not login No result from call to login

Can someone please help?

Would you mind explaining why you’re trying to login with a Meteor method call and not simply use the function directly?

Thanks @rhywden for the reply!
I thought it was best to have all user related methods in a separate file.
I am able to call Meteor.loginwithpassword from the same page and it returns ‘success’.

What is the best practice, use a wrapper or no?

Short and to the point: No.

ok.

but what does the error mean by itself, can you explain?

Thanks

You are trying to call a Meteor method only on the client. But Meteor methods are always living on the server and are also optionally on the client.

Which means your call to the loginUser method went to the server and didn’t find the definition there.

Meteor methods are intended to define methods which you can’t trust the client with - such as mass insertions, deletions and so on. As such, they always have to be defined on the server.

You should read this again: https://guide.meteor.com/methods.html

That was very helpful.
Thank you!

You can still call it: if (Meteor.isClient) {
Meteor.loginWithPassword…

There will be same error but your response does not explain the error.