Abort meteor.loginwithpassword from client

Is there a way to abort meteor.loginwithpassword from the client?
In case the server fails or the db is slow etc?

I’ve added a timeout to close any loaders etc, but I also don’t want it to come back later on completed.

from the docs:

Meteor.loginWithPassword(selector, password, [callback])

The [callback] argument is a function that is run after the login method.
Why abort, if every error is received in the callback as the first argument?
Why not do something like this:

(err, res) => {
  if(err){
    // Error in login method
  }
// Stop loaders and stuff
}

I can’t see a reason for the abort…

Im looking for a way to cancel the login attempt from the client if the server does not reply for some reason, I had a situation where the mongoDB was hanging and the server was waiting for mongo to reply to continue the login process, but the client was left hanging there.

I’ve added a timeout on the client, to provide feedback that the system hasn’t replied, but I’m looking for a way to actually cancel that attempt too.

Can you maybe try to do this on the server? set timeout for the login method and throw an error or return it when the timeout is up.

But the fact that the mongo hangs up is a bigger problem, no?
I mean, why handling an error like this when it shouldn’t happen in the first place? Why not just solve the mongo hangup problem?

Either way, I would look into the reason why mongo was slowing down, and if I couldn’t solve it then isolate the login method on the server inside a Meteor_setTimeout() function and throw errors when the time is up.

About canceling meteor methods: Cancelling an already-made method call to the server from the client is not possible. given that the Method is actually run twice, once on the client minimongo and once on the server.

I read an interesting tweet about Promise.race, maybe it can help.

1 Like