docs: function (methodInvocation, methodName, methodArgs, result) {
    if (!result)
      throw new Error("result is required");
  
    // XXX A programming error in a login handler can lead to this occuring, and
    // then we don't call onLogin or onLoginFailure callbacks. Should
    // tryLoginMethod catch this case and turn it into an error?
    if (!result.userId && !result.error)
      throw new Error("A login method must specify a userId or an error");
  
    var user;
    if (result.userId)
      user = Meteor.users.findOne(result.userId);
  
    var attempt = {
      type: result.type || "unknown",
      allowed: !! (result.userId && !result.error),
      methodName: methodName,
      methodArguments: _.toArray(methodArgs)
    };
    if (result.error)
      attempt.error = result.error;
    if (user)
      attempt.user = user;
  
    // validateLogin may mutate `attempt` by adding an error and changing allowed
    // to false, but that's the only change it can make (and the user's callbacks
    // only get a clone of `attempt`).
    validateLogin(methodInvocation.connection, attempt);
  
    if (attempt.allowed) {
      var ret = _.extend(
        loginUser(methodInvocation, result.userId, result.stampedLoginToken),
        result.options || {}
      );
      successfulLogin(methodInvocation.connection, attempt);
      return ret;
    }
    else {
      failedLogin(methodInvocation.connection, attempt);
      throw attempt.error;
    }
  }