Meteor.loginWithPassword Mobile Question

So I updated my meteor app on the Android Simulator.

try {
 Meteor.loginWithPassword(email, password, function(error) {
  console.log('loginwithpassword')
 });
} catch (e) {
 console.log('err: ' + e);
}

EDIT: Formatting my code

Works well when the meteor server is reachable. But once you shut it down, the callback of loginWithPassword is not called. Did any one get past this?

Did you try:

Meteor.loginWithPassword(email, password, function(error) {
  if (error) {
    console.log('err: ' + error);
  }  else {
    console.log('loginwithpassword');
  }
});

also, you can wrap that with a status check

if (Meteor.status().status === "connected") {
  Meteor.loginWithPassword(email, password, function(error) {
    if (error) {
      console.log('err: ' + error);
    }  else {
      console.log('loginwithpassword');
    }
  });
} else {
  console.log("There is no connection");
}

so that you don’t initiate a login when there is no connection.

You can also use Meteor.status().status === "connected" check in a helper to display/hide the login button itself for better UX.

1 Like

It does not reach the call back. I did consider status check, but then i would have to make status check reactive (?) so that all my buttons go disabled when people turn off WiFI and cellular. The thing is: I am disabling a button before signing in. And it gets enabled only when the login callback is called.

Hm, makes sense. Since there is no response, there is no callback. I’d assume an error with timeout though, but since the callback is what the server returns, the case of “there is no server” is to be handled separately.

The status check is already reactive so you can use it in such regard.

I don’t understand what you mean by disabling the button before sign-in.

If you have some separate logic for the state of the login button, you can always combine that logic with an and operator to the status check.