Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
Why does this Firebase web authentication function 'onAuthStateChanged' occasionally not fire?

Why does this Firebase web authentication function 'onAuthStateChanged' occasionally not fire?

The intention of this code is to use Firebase for Web (JavaScript) and automatically sign-up visitors to the website as an anonymous user, however if they created an account using email and the anonymous sign-in is ignored.

Symptoms of this issue are:

  • At random, maybe 2% of the time, the function 'onAuthStateChanged' does not fire at all.
  • Refreshing the browser does not fix the issue
  • Closing and reopening the tab does fix the issue
  • Mostly happens on the Chrome iOS app, but not only.

When this happens, the debug statements look like this:

  • loaded 4

  • loaded 5

  • loaded 6

  • loaded 7

  • loaded 8

~98% of the time this code works as intended but around 2% of the time is does not work at all and the user must close and reopen the tab and I can't figure out why. Does anyone know what's wrong?

    console.log("loaded 4");
    const analytics = getAnalytics(app);
    console.log("loaded 5");
    const db = getFirestore(app);
    console.log("loaded 6");
    const functions = getFunctions(app);
    console.log("loaded 7");
    const auth = getAuth();
    console.log("loaded 8");

    onAuthStateChanged(auth, (user) => {
      console.log("initiate on auth state change")

      if (user) {
        console.log("signed is as something")
        fuctionToLoadStuff();

        let uid = user.uid;
        const isAnon = user.isAnonymous;
        if (isAnon == true) {
          console.log("User is signed in anonymously as " + uid);
          annonUserStuff(uid);

        } else {
          console.log("User is signed into an account as " + uid);
          getProfile(uid);
        }
      } else {
        console.log("signed is as nothing");
        signInAnonymously(auth)
          .then(() => {
            const uid = auth.currentUser.uid;
            console.log("Anon user acct created");
          functionForANewAnonUser(uid);
          })
          .catch((error) => {
            const errorCode = error.code;
            const errorMessage = error.message;
            console.log(errorMessage);
          });
      }
    });

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda