Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda