function()

in javascript/widgets/handler/callback.js [157:227]


    function(app, component, result) {
  if (result['user']) {
    var authResult = /** @type {!firebaseui.auth.widget.Config.AuthResult} */ ({
      'user': result['user'],
      'credential': result['credential'],
      'operationType': result['operationType'],
      'additionalUserInfo': result['additionalUserInfo']
    });
    // Sign in or link with redirect was previously triggered.
    var pendingEmailCredential =
        firebaseui.auth.storage.getPendingEmailCredential(app.getAppId());
    // The email originally used before the federated sign in, if any.
    var pendingEmail =
        pendingEmailCredential && pendingEmailCredential.getEmail();
    // Test for email mismatch cases.
    if (pendingEmail &&
        !firebaseui.auth.widget.handler.hasUserEmailAddress_(
            result['user'], pendingEmail)) {
      // The user tried originally to sign in with a different
      // email than the one coming from the provider.
      firebaseui.auth.widget.handler.handleCallbackEmailMismatch_(
          app, component, authResult);
      return;
    }
    var pendingCredential =
        pendingEmailCredential && pendingEmailCredential.getCredential();
    if (pendingCredential) {
      // Check if there is a pending auth credential. If so, complete the link
      // process and delete the pending credential.
      app.registerPending(result['user'].linkWithCredential(pendingCredential)
          .then(function(userCredential) {
            // Linking successful, complete sign in, pass pending credentials
            // as the developer originally expected them in the sign in
            // attempt that triggered the link.
            authResult = (
                /** @type {!firebaseui.auth.widget.Config.AuthResult} */ ({
                  'user': userCredential['user'],
                  'credential': pendingCredential,
                  // Even though the operation type returned here is always
                  // 'link', we will sign in again on external Auth instance
                  // with this credential returning 'signIn' or 'link' in case
                  // of anonymous upgrade through
                  // finishSignInAndRetrieveDataWithAuthResult.
                  'operationType': userCredential['operationType'],
                  'additionalUserInfo': userCredential['additionalUserInfo']
                }));
            firebaseui.auth.widget.handler.handleCallbackSuccess_(
                app, component, authResult);
          },
          function(error) {
            // Go to the sign-in page with info bar error.
            firebaseui.auth.widget.handler.handleCallbackFailure_(
                app, component, error);
          }));
    } else {
      // No pending credential, complete sign in.
      firebaseui.auth.widget.handler.handleCallbackSuccess_(
          app, component, authResult);
    }
  } else {
    // No previous redirect operation, go back to the sign-in page with no
    // error.
    var container = component.getContainer();
    component.dispose();
    // Clean the pending email credential, if any, to avoid keeping track of
    // a linking flow after the user has refreshed the page (i.e. when no more
    // redirect result).
    firebaseui.auth.storage.removePendingEmailCredential(app.getAppId());
    firebaseui.auth.widget.handler.common.handleSignInStart(app, container);
  }
};