code: function (methodInvocation, userId, stampedLoginToken) {
    if (! stampedLoginToken) {
      stampedLoginToken = Accounts._generateStampedLoginToken();
      Accounts._insertLoginToken(userId, stampedLoginToken);
    }
  
    // This order (and the avoidance of yields) is important to make
    // sure that when publish functions are rerun, they see a
    // consistent view of the world: the userId is set and matches
    // the login token on the connection (not that there is
    // currently a public API for reading the login token on a
    // connection).
    Meteor._noYieldsAllowed(function () {
      Accounts._setLoginToken(
        userId,
        methodInvocation.connection,
        Accounts._hashLoginToken(stampedLoginToken.token)
      );
    });
  
    methodInvocation.setUserId(userId);
  
    return {
      id: userId,
      token: stampedLoginToken.token,
      tokenExpires: Accounts._tokenExpiration(stampedLoginToken.when)
    };
  }
docs: Log in a user on a connection.  We use the method invocation to set the user id on the connection, not the connection object directly. setUserId is tied to methods to enforce clear ordering of method application (using wait methods on the client, and a no setUserId after unblock restriction on the server)  The `stampedLoginToken` parameter is optional.  When present, it indicates that the login token has already been inserted into the database and doesn't need to be inserted again.  (It's used by the "resume" login handler).