firebaseui.auth.widget.handler.completeEmailLinkSignIn_ = function()

in javascript/widgets/handler/emaillinksignincallback.js [257:334]


firebaseui.auth.widget.handler.completeEmailLinkSignIn_ = function(
    app, component, email, link, credential, user) {
  var container = component.getContainer();
  // Display the progress dialog while the user is being signed in or upgraded.
  component.showProgressDialog(
      firebaseui.auth.ui.element.progressDialog.State.LOADING,
      firebaseui.auth.soy2.strings.dialogEmailLinkProcessing().toString());
  var signInPromise = user ?
      app.upgradeWithEmailLink(user, email, link, credential) :
      app.signInWithEmailLink(email, link, credential);
  var timer = null;
  var p = signInPromise
      .then(function(authResult) {
        // Clear credentials and email on success.
        firebaseui.auth.storage.removeEncryptedPendingCredential(
            app.getAppId());
        firebaseui.auth.storage.removeEmailForSignIn(app.getAppId());
        // Clear UI.
        component.dismissDialog();
        component.showProgressDialog(
            firebaseui.auth.ui.element.progressDialog.State.DONE,
            firebaseui.auth.soy2.strings.dialogEmailLinkVerified().toString());
        // Trigger completion callback after some delay showing the sign in
        // success dialog.
        timer = setTimeout(function() {
          component.dismissDialog();
          firebaseui.auth.widget.handler.common
              .setLoggedInWithAuthResult(app, component, authResult, true);
        }, firebaseui.auth.widget.handler.SIGN_IN_SUCCESS_DIALOG_DELAY);
        // If the UI is reset, the timer should be cleared and any visible UI
        // dismissed.
        app.registerPending(function() {
          if (component) {
            component.dismissDialog();
            component.dispose();
          }
          clearTimeout(timer);
        });
      }, function(error) {
        component.dismissDialog();
        component.dispose();
        if (error['name'] && error['name'] == 'cancel') {
          return;
        }
        const normalizedError =
            firebaseui.auth.widget.handler.common.normalizeError(error);
        let errorMessage =
            firebaseui.auth.widget.handler.common.getErrorMessage(
                normalizedError);
        if (normalizedError['code'] == 'auth/email-already-in-use' ||
            normalizedError['code'] == 'auth/credential-already-in-use') {
          // Clear credentials and email before handing off credential to
          // developer.
          firebaseui.auth.storage.removeEncryptedPendingCredential(
              app.getAppId());
          firebaseui.auth.storage.removeEmailForSignIn(app.getAppId());
        } else if (normalizedError['code'] == 'auth/invalid-email') {
          // User provided an invalid email. Ask for confirmation again.
          // On email confirmation, call this handler again with
          // skipCodeCheck set to true.
          errorMessage =
              firebaseui.auth.soy2.strings.errorMismatchingEmail().toString();
          firebaseui.auth.widget.handler.handle(
              firebaseui.auth.widget.HandlerName.EMAIL_LINK_CONFIRMATION,
              app,
              container,
              link,
              firebaseui.auth.widget.handler.completeEmailConfirmation_,
              null,
              errorMessage);
        } else {
          firebaseui.auth.widget.handler.common.handleSignInStart(
              app, container, email, errorMessage);
        }
      });
  app.registerPending(p);
  return p;
};