var cb = function()

in javascript/widgets/authui.js [307:352]


    var cb = function(user) {
      if (user &&
          // If email already exists, user must first be signed in it to the
          // existing account on the internal Auth instance before the
          // credential is linked and merge conflict is triggered.
          !firebaseui.auth.storage.getPendingEmailCredential(self.getAppId())) {
        // Anonymous user eligible for upgrade detected.
        // Linking occurs on external Auth instance.
        // This could occur when anonymous user linking with redirect fails for
        // some reason.
        return /** @type {!goog.Promise<!firebase.auth.UserCredential>} */ (
            goog.Promise.resolve(self.getExternalAuth().getRedirectResult()
            .then(function(result) {
              // Should not happen in real life as this will only run when the
              // user is anonymous.
              return result;
             }, function(error) {
              // This will trigger account linking flow.
              if (error &&
                  error['code'] == 'auth/email-already-in-use' &&
                  error['email'] && error['credential']) {
                throw error;
              }
              return self.onUpgradeError(error);
            })));
      } else {
        // No eligible anonymous user detected on external instance.
        // Get redirect result from internal instance first.
        return goog.Promise.resolve(
            self.getAuth().getRedirectResult().then(function(result) {
              // Anonymous user could have successfully completed
              // linkWithRedirect.
              if (self.getConfig().autoUpgradeAnonymousUsers() &&
                  // No user signed in on internal instance.
                  !result['user'] &&
                  // Current non anonymous user available on external instance.
                  self.currentUser_ &&
                  !self.currentUser_['isAnonymous']) {
                // Return redirect result from external instance.
                return self.getExternalAuth().getRedirectResult();
              }
              // Return redirect result from internal instance.
              return result;
            }));
      }
    };