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

311
Visualizações
TypeError: _app.default.auth is not a function - React Native Web - Firebase

I am currently developing a project on React Native Web and this is my login call in a component. (The call is in the components useEffect, as soon as the component opens, it should log in anonymously)

import firebase from 'firebase/compat/app'
import 'firebase/compat/auth'
const firebaseConfig = {
        apiKey: "****",
        authDomain: "****",
        projectId: "****",
        storageBucket: "****",
        messagingSenderId: "****",
        appId: "****",
        measurementId: "****"
      };
      firebase.initializeApp(firebaseConfig) 

const login = async () => {
        firebase.auth().signInAnonymously() 
            .then((userCredential) => {
                // Signed in
                // ...
              })
              .catch((error) => {
                console.log("LOG: "+error)
              });
    } 

But everytime I get the error: Uncaught (in promise) TypeError: _app.default.auth is not a function

I tried several different imports, but none of them seemed to work. I see the error when I open the Console on Firefox. How can I fix this issue?

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try this approach by checking if firebase is initialized and the user is not logged in:

const [loggedIn, setLoggedIn] = React.useState(false)

React.useEffect(() => {
    if (!firebase.apps.length) {
        firebase.initializeApp({
            apiKey: "****",
            authDomain: "****",
            projectId: "****",
            storageBucket: "****",
            messagingSenderId: "****",
            appId: "****",
            measurementId: "****"
        });
    }
}, [])

React.useEffect(() => {
    if (firebase.apps.length && !loggedIn) {
        setLoggedIn(true)
        login()
    }
}, [firebase])

const login = async () => {
    firebase.auth().signInAnonymously()
        .then((userCredential) => {
            // Signed in
            // ...
        })
        .catch((error) => {
            console.log("LOG: " + error)
        });
} 
about 4 years ago · Juan Pablo Isaza Relatório
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