function initApp(){
  log('Initializing app...');
  app = firebase.initializeApp(config);
  auth = app.auth();

  tempApp = firebase.initializeApp({
    'apiKey': config['apiKey'],
    'authDomain': config['authDomain']
  }, auth['app']['name'] + '-temp');
  tempAuth = tempApp.auth();

  // Listen to reCAPTCHA config togglers.
  initRecaptchaToggle(function(size) {
    clearApplicationVerifier();
    recaptchaSize = size;
  });

  // The action code for email verification or password reset
  // can be passed in the url address as a parameter, and for convenience
  // this preloads the input field.
  populateActionCodes();

  // Allows to login the user if previously logged in.
  if (auth.onIdTokenChanged) {
    auth.onIdTokenChanged(function(user) {
      refreshUserData();
      if (user) {
        user.getIdTokenResult(false).then(
          function(idTokenResult) {
            log(JSON.stringify(idTokenResult));
          },
          function() {
            log('No token.');
          }
         );
      } else {
        log('No user logged in.');
      }
    });
  }

  if (auth.onAuthStateChanged) {
    auth.onAuthStateChanged(function(user) {
      if (user) {
        log('user state change detected: ' + user.uid);
      } else {
        log('user state change detected: no user');
      }
      // Check Database Auth access.
      checkDatabaseAuthAccess();
    });
  }

  if (tempAuth.onAuthStateChanged) {
    tempAuth.onAuthStateChanged(function(user) {
      if (user) {
        log('user state change on temp Auth detect: ' + JSON.stringify(user));
        alertSuccess('user state change on temp Auth detect: ' + user.uid);
      }
    });
  }

  // We check for redirect result to refresh user's data.
  auth.getRedirectResult().then(function(response) {
    refreshUserData();
    logAdditionalUserInfo(response);
  }, onAuthError);

  // Bootstrap tooltips.
  $('[data-toggle="tooltip"]').tooltip();

  // Auto submit the choose library type form.
  $('#library-form').on('change', 'input.library-option', function() {
    $('#library-form').submit();
  });

  // To clear the logs in the page.
  $('.clear-logs').click(clearLogs);

  // Disables JS forms.
  $('form.no-submit').on('submit', function() {
    return false;
  });

  // Keeps track of the current tab opened.
  $('#tab-menu a').click(function(event) {
    currentTab = $(event.currentTarget).attr("href");
  });

  // Toggles user.
  $('input[name=toggle-user-selection]').change(refreshUserData);

  // Actions listeners.
  $('#sign-up-with-email-and-password').click(onSignUp);
  $('#sign-in-with-email-and-password').click(onSignInWithEmailAndPassword);
  $('.sign-in-with-custom-token').click(onSignInWithCustomToken);
  $('#sign-in-anonymously').click(onSignInAnonymously);
  $('#sign-in-with-generic-idp-credential')
      .click(onSignInWithGenericIdPCredential);
  $('#signin-verify-phone-number').click(onSignInVerifyPhoneNumber);
  $('#signin-confirm-phone-verification')
      .click(onSignInConfirmPhoneVerification);
  // On enter click in verification code, complete phone sign-in. This prevents
  // reCAPTCHA from being re-rendered (default behavior on enter).
  $('#signin-phone-verification-code').keypress(function(e) {
    if (e.which == 13) {
      onSignInConfirmPhoneVerification();
      e.preventDefault();
    }
  });
  $('#sign-in-with-email-link').click(onSignInWithEmailLink);
  $('#link-with-email-link').click(onLinkWithEmailLink);
  $('#reauth-with-email-link').click(onReauthenticateWithEmailLink);

  $('#change-email').click(onChangeEmail);
  $('#change-password').click(onChangePassword);
  $('#update-profile').click(onUpdateProfile);

  $('#send-sign-in-link-to-email').click(onSendSignInLinkToEmail);
  $('#send-sign-in-link-to-email-current-url')
      .click(onSendSignInLinkToEmailCurrentUrl);
  $('#send-link-email-link').click(onSendLinkEmailLink);

  $('#send-password-reset-email').click(onSendPasswordResetEmail);
  $('#verify-password-reset-code').click(onVerifyPasswordResetCode);
  $('#confirm-password-reset').click(onConfirmPasswordReset);

  $('#get-provider-data').click(onGetProviderData);
  $('#link-with-email-and-password').click(onLinkWithEmailAndPassword);
  $('#link-with-generic-idp-credential').click(onLinkWithGenericIdPCredential);
  $('#unlink-provider').click(onUnlinkProvider);
  $('#link-reauth-verify-phone-number').click(onLinkReauthVerifyPhoneNumber);
  $('#update-confirm-phone-verification')
      .click(onUpdateConfirmPhoneVerification);
  $('#link-confirm-phone-verification').click(onLinkConfirmPhoneVerification);
  $('#reauth-confirm-phone-verification')
      .click(onReauthConfirmPhoneVerification);
  // On enter click in verification code, complete phone sign-in. This prevents
  // reCAPTCHA from being re-rendered (default behavior on enter).
  $('#link-reauth-phone-verification-code').keypress(function(e) {
    if (e.which == 13) {
      // User first option option as default.
      onUpdateConfirmPhoneVerification();
      e.preventDefault();
    }
  });

  $('#send-email-verification').click(onSendEmailVerification);
  $('#confirm-email-verification').click(onApplyActionCode);
  $('#get-token-result').click(onGetIdTokenResult);
  $('#refresh-token-result').click(onRefreshTokenResult);
  $('#get-token').click(onGetIdToken);
  $('#refresh-token').click(onRefreshToken);
  $('#get-token-worker').click(onGetCurrentUserDataFromWebWorker);
  $('#sign-out').click(onSignOut);

  $('.popup-redirect-provider').click(onPopupRedirectProviderClick);
  $('#popup-redirect-generic').click(onPopupRedirectGenericProviderClick);
  $('#popup-redirect-get-redirect-result').click(onGetRedirectResult);
  $('#popup-redirect-add-custom-parameter')
      .click(onPopupRedirectAddCustomParam);
  $('#popup-redirect-saml').click(onPopupRedirectSamlProviderClick);

  $('#action-code-settings-reset').click(onActionCodeSettingsReset);

  $('#delete').click(onDelete);

  $('#set-persistence').click(onSetPersistence);

  $('#set-language-code').click(onSetLanguageCode);
  $('#use-device-language').click(onUseDeviceLanguage);

  $('#fetch-sign-in-methods-for-email').click(onFetchSignInMethodsForEmail);

  $('#run-web-worker-tests').click(onRunWebWorkTests);
  $('#run-service-worker-tests').click(onRunServiceWorkTests);
  $('#copy-active-user').click(onCopyActiveUser);
  $('#copy-last-user').click(onCopyLastUser);

  $('#apply-auth-settings-change').click(onApplyAuthSettingsChange);
}
function initApp(){
  log('Initializing app...');
  app = firebase.initializeApp(config);
  auth = app.auth();

  tempApp = firebase.initializeApp({
    'apiKey': config['apiKey'],
    'authDomain': config['authDomain']
  }, auth['app']['name'] + '-temp');
  tempAuth = tempApp.auth();

  // Listen to reCAPTCHA config togglers.
  initRecaptchaToggle(function(size) {
    clearApplicationVerifier();
    recaptchaSize = size;
  });

  // The action code for email verification or password reset
  // can be passed in the url address as a parameter, and for convenience
  // this preloads the input field.
  populateActionCodes();

  // Allows to login the user if previously logged in.
  if (auth.onIdTokenChanged) {
    auth.onIdTokenChanged(function(user) {
      refreshUserData();
      if (user) {
        user.getIdTokenResult(false).then(
          function(idTokenResult) {
            log(JSON.stringify(idTokenResult));
          },
          function() {
            log('No token.');
          }
         );
      } else {
        log('No user logged in.');
      }
    });
  }

  if (auth.onAuthStateChanged) {
    auth.onAuthStateChanged(function(user) {
      if (user) {
        log('user state change detected: ' + user.uid);
      } else {
        log('user state change detected: no user');
      }
      // Check Database Auth access.
      checkDatabaseAuthAccess();
    });
  }

  if (tempAuth.onAuthStateChanged) {
    tempAuth.onAuthStateChanged(function(user) {
      if (user) {
        log('user state change on temp Auth detect: ' + JSON.stringify(user));
        alertSuccess('user state change on temp Auth detect: ' + user.uid);
      }
    });
  }

  // We check for redirect result to refresh user's data.
  auth.getRedirectResult().then(function(response) {
    refreshUserData();
    logAdditionalUserInfo(response);
  }, onAuthError);

  // Bootstrap tooltips.
  $('[data-toggle="tooltip"]').tooltip();

  // Auto submit the choose library type form.
  $('#library-form').on('change', 'input.library-option', function() {
    $('#library-form').submit();
  });

  // To clear the logs in the page.
  $('.clear-logs').click(clearLogs);

  // Disables JS forms.
  $('form.no-submit').on('submit', function() {
    return false;
  });

  // Keeps track of the current tab opened.
  $('#tab-menu a').click(function(event) {
    currentTab = $(event.currentTarget).attr("href");
  });

  // Toggles user.
  $('input[name=toggle-user-selection]').change(refreshUserData);

  // Actions listeners.
  $('#sign-up-with-email-and-password').click(onSignUp);
  $('#sign-in-with-email-and-password').click(onSignInWithEmailAndPassword);
  $('.sign-in-with-custom-token').click(onSignInWithCustomToken);
  $('#sign-in-anonymously').click(onSignInAnonymously);
  $('#sign-in-with-generic-idp-credential')
      .click(onSignInWithGenericIdPCredential);
  $('#signin-verify-phone-number').click(onSignInVerifyPhoneNumber);
  $('#signin-confirm-phone-verification')
      .click(onSignInConfirmPhoneVerification);
  // On enter click in verification code, complete phone sign-in. This prevents
  // reCAPTCHA from being re-rendered (default behavior on enter).
  $('#signin-phone-verification-code').keypress(function(e) {
    if (e.which == 13) {
      onSignInConfirmPhoneVerification();
      e.preventDefault();
    }
  });
  $('#sign-in-with-email-link').click(onSignInWithEmailLink);
  $('#link-with-email-link').click(onLinkWithEmailLink);
  $('#reauth-with-email-link').click(onReauthenticateWithEmailLink);

  $('#change-email').click(onChangeEmail);
  $('#change-password').click(onChangePassword);
  $('#update-profile').click(onUpdateProfile);

  $('#send-sign-in-link-to-email').click(onSendSignInLinkToEmail);
  $('#send-sign-in-link-to-email-current-url')
      .click(onSendSignInLinkToEmailCurrentUrl);
  $('#send-link-email-link').click(onSendLinkEmailLink);

  $('#send-password-reset-email').click(onSendPasswordResetEmail);
  $('#verify-password-reset-code').click(onVerifyPasswordResetCode);
  $('#confirm-password-reset').click(onConfirmPasswordReset);

  $('#get-provider-data').click(onGetProviderData);
  $('#link-with-email-and-password').click(onLinkWithEmailAndPassword);
  $('#link-with-generic-idp-credential').click(onLinkWithGenericIdPCredential);
  $('#unlink-provider').click(onUnlinkProvider);
  $('#link-reauth-verify-phone-number').click(onLinkReauthVerifyPhoneNumber);
  $('#update-confirm-phone-verification')
      .click(onUpdateConfirmPhoneVerification);
  $('#link-confirm-phone-verification').click(onLinkConfirmPhoneVerification);
  $('#reauth-confirm-phone-verification')
      .click(onReauthConfirmPhoneVerification);
  // On enter click in verification code, complete phone sign-in. This prevents
  // reCAPTCHA from being re-rendered (default behavior on enter).
  $('#link-reauth-phone-verification-code').keypress(function(e) {
    if (e.which == 13) {
      // User first option option as default.
      onUpdateConfirmPhoneVerification();
      e.preventDefault();
    }
  });

  $('#send-email-verification').click(onSendEmailVerification);
  $('#confirm-email-verification').click(onApplyActionCode);
  $('#get-token-result').click(onGetIdTokenResult);
  $('#refresh-token-result').click(onRefreshTokenResult);
  $('#get-token').click(onGetIdToken);
  $('#refresh-token').click(onRefreshToken);
  $('#get-token-worker').click(onGetCurrentUserDataFromWebWorker);
  $('#sign-out').click(onSignOut);

  $('.popup-redirect-provider').click(onPopupRedirectProviderClick);
  $('#popup-redirect-generic').click(onPopupRedirectGenericProviderClick);
  $('#popup-redirect-get-redirect-result').click(onGetRedirectResult);
  $('#popup-redirect-add-custom-parameter')
      .click(onPopupRedirectAddCustomParam);
  $('#popup-redirect-saml').click(onPopupRedirectSamlProviderClick);

  $('#action-code-settings-reset').click(onActionCodeSettingsReset);

  $('#delete').click(onDelete);

  $('#set-persistence').click(onSetPersistence);

  $('#set-language-code').click(onSetLanguageCode);
  $('#use-device-language').click(onUseDeviceLanguage);

  $('#fetch-sign-in-methods-for-email').click(onFetchSignInMethodsForEmail);

  $('#run-web-worker-tests').click(onRunWebWorkTests);
  $('#run-service-worker-tests').click(onRunServiceWorkTests);
  $('#copy-active-user').click(onCopyActiveUser);
  $('#copy-last-user').click(onCopyLastUser);

  $('#apply-auth-settings-change').click(onApplyAuthSettingsChange);
}
function initApp ( ) { log ( 'Initializing app...' ) ; app = firebase . initializeApp ( config ) ; auth = app . auth ( ) ; tempApp = firebase . initializeApp ( { 'apiKey' : config [ 'apiKey' ] , 'authDomain' : config [ 'authDomain' ] } , auth [ 'app' ] [ 'name' ] + '-temp' ) ; tempAuth = tempApp . auth ( ) ; // Listen to reCAPTCHA config togglers. initRecaptchaToggle ( function ( size ) { clearApplicationVerifier ( ) ; recaptchaSize = size ; } ) ; // The action code for email verification or password reset // can be passed in the url address as a parameter, and for convenience // this preloads the input field. populateActionCodes ( ) ; // Allows to login the user if previously logged in. if ( auth . onIdTokenChanged ) { auth . onIdTokenChanged ( function ( user ) { refreshUserData ( ) ; if ( user ) { user . getIdTokenResult ( false ) . then ( function ( idTokenResult ) { log ( JSON . stringify ( idTokenResult ) ) ; } , function ( ) { log ( 'No token.' ) ; } ) ; } else { log ( 'No user logged in.' ) ; } } ) ; } if ( auth . onAuthStateChanged ) { auth . onAuthStateChanged ( function ( user ) { if ( user ) { log ( 'user state change detected: ' + user . uid ) ; } else { log ( 'user state change detected: no user' ) ; } // Check Database Auth access. checkDatabaseAuthAccess ( ) ; } ) ; } if ( tempAuth . onAuthStateChanged ) { tempAuth . onAuthStateChanged ( function ( user ) { if ( user ) { log ( 'user state change on temp Auth detect: ' + JSON . stringify ( user ) ) ; alertSuccess ( 'user state change on temp Auth detect: ' + user . uid ) ; } } ) ; } // We check for redirect result to refresh user's data. auth . getRedirectResult ( ) . then ( function ( response ) { refreshUserData ( ) ; logAdditionalUserInfo ( response ) ; } , onAuthError ) ; // Bootstrap tooltips. $ ( '[data-toggle="tooltip"]' ) . tooltip ( ) ; // Auto submit the choose library type form. $ ( '#library-form' ) . on ( 'change' , 'input.library-option' , function ( ) { $ ( '#library-form' ) . submit ( ) ; } ) ; // To clear the logs in the page. $ ( '.clear-logs' ) . click ( clearLogs ) ; // Disables JS forms. $ ( 'form.no-submit' ) . on ( 'submit' , function ( ) { return false ; } ) ; // Keeps track of the current tab opened. $ ( '#tab-menu a' ) . click ( function ( event ) { currentTab = $ ( event . currentTarget ) . attr ( "href" ) ; } ) ; // Toggles user. $ ( 'input[name=toggle-user-selection]' ) . change ( refreshUserData ) ; // Actions listeners. $ ( '#sign-up-with-email-and-password' ) . click ( onSignUp ) ; $ ( '#sign-in-with-email-and-password' ) . click ( onSignInWithEmailAndPassword ) ; $ ( '.sign-in-with-custom-token' ) . click ( onSignInWithCustomToken ) ; $ ( '#sign-in-anonymously' ) . click ( onSignInAnonymously ) ; $ ( '#sign-in-with-generic-idp-credential' ) . click ( onSignInWithGenericIdPCredential ) ; $ ( '#signin-verify-phone-number' ) . click ( onSignInVerifyPhoneNumber ) ; $ ( '#signin-confirm-phone-verification' ) . click ( onSignInConfirmPhoneVerification ) ; // On enter click in verification code, complete phone sign-in. This prevents // reCAPTCHA from being re-rendered (default behavior on enter). $ ( '#signin-phone-verification-code' ) . keypress ( function ( e ) { if ( e . which == 13 ) { onSignInConfirmPhoneVerification ( ) ; e . preventDefault ( ) ; } } ) ; $ ( '#sign-in-with-email-link' ) . click ( onSignInWithEmailLink ) ; $ ( '#link-with-email-link' ) . click ( onLinkWithEmailLink ) ; $ ( '#reauth-with-email-link' ) . click ( onReauthenticateWithEmailLink ) ; $ ( '#change-email' ) . click ( onChangeEmail ) ; $ ( '#change-password' ) . click ( onChangePassword ) ; $ ( '#update-profile' ) . click ( onUpdateProfile ) ; $ ( '#send-sign-in-link-to-email' ) . click ( onSendSignInLinkToEmail ) ; $ ( '#send-sign-in-link-to-email-current-url' ) . click ( onSendSignInLinkToEmailCurrentUrl ) ; $ ( '#send-link-email-link' ) . click ( onSendLinkEmailLink ) ; $ ( '#send-password-reset-email' ) . click ( onSendPasswordResetEmail ) ; $ ( '#verify-password-reset-code' ) . click ( onVerifyPasswordResetCode ) ; $ ( '#confirm-password-reset' ) . click ( onConfirmPasswordReset ) ; $ ( '#get-provider-data' ) . click ( onGetProviderData ) ; $ ( '#link-with-email-and-password' ) . click ( onLinkWithEmailAndPassword ) ; $ ( '#link-with-generic-idp-credential' ) . click ( onLinkWithGenericIdPCredential ) ; $ ( '#unlink-provider' ) . click ( onUnlinkProvider ) ; $ ( '#link-reauth-verify-phone-number' ) . click ( onLinkReauthVerifyPhoneNumber ) ; $ ( '#update-confirm-phone-verification' ) . click ( onUpdateConfirmPhoneVerification ) ; $ ( '#link-confirm-phone-verification' ) . click ( onLinkConfirmPhoneVerification ) ; $ ( '#reauth-confirm-phone-verification' ) . click ( onReauthConfirmPhoneVerification ) ; // On enter click in verification code, complete phone sign-in. This prevents // reCAPTCHA from being re-rendered (default behavior on enter). $ ( '#link-reauth-phone-verification-code' ) . keypress ( function ( e ) { if ( e . which == 13 ) { // User first option option as default. onUpdateConfirmPhoneVerification ( ) ; e . preventDefault ( ) ; } } ) ; $ ( '#send-email-verification' ) . click ( onSendEmailVerification ) ; $ ( '#confirm-email-verification' ) . click ( onApplyActionCode ) ; $ ( '#get-token-result' ) . click ( onGetIdTokenResult ) ; $ ( '#refresh-token-result' ) . click ( onRefreshTokenResult ) ; $ ( '#get-token' ) . click ( onGetIdToken ) ; $ ( '#refresh-token' ) . click ( onRefreshToken ) ; $ ( '#get-token-worker' ) . click ( onGetCurrentUserDataFromWebWorker ) ; $ ( '#sign-out' ) . click ( onSignOut ) ; $ ( '.popup-redirect-provider' ) . click ( onPopupRedirectProviderClick ) ; $ ( '#popup-redirect-generic' ) . click ( onPopupRedirectGenericProviderClick ) ; $ ( '#popup-redirect-get-redirect-result' ) . click ( onGetRedirectResult ) ; $ ( '#popup-redirect-add-custom-parameter' ) . click ( onPopupRedirectAddCustomParam ) ; $ ( '#popup-redirect-saml' ) . click ( onPopupRedirectSamlProviderClick ) ; $ ( '#action-code-settings-reset' ) . click ( onActionCodeSettingsReset ) ; $ ( '#delete' ) . click ( onDelete ) ; $ ( '#set-persistence' ) . click ( onSetPersistence ) ; $ ( '#set-language-code' ) . click ( onSetLanguageCode ) ; $ ( '#use-device-language' ) . click ( onUseDeviceLanguage ) ; $ ( '#fetch-sign-in-methods-for-email' ) . click ( onFetchSignInMethodsForEmail ) ; $ ( '#run-web-worker-tests' ) . click ( onRunWebWorkTests ) ; $ ( '#run-service-worker-tests' ) . click ( onRunServiceWorkTests ) ; $ ( '#copy-active-user' ) . click ( onCopyActiveUser ) ; $ ( '#copy-last-user' ) . click ( onCopyLastUser ) ; $ ( '#apply-auth-settings-change' ) . click ( onApplyAuthSettingsChange ) ; }
Initiates the application by setting event listeners on the various buttons.
Initiates the application by setting event listeners on the various buttons .
Initializes the app.