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

204
Visualizações
How to check If registered user when login with google using firebase in react js?

i want to check if the person logged in with Google account, has registered before or not to save to Firestore. Is there any way to check?

 const ggProvider = new GoogleAuthProvider();

 const handleGgLogin = async () => {
    const { user } = await signInWithPopup(auth, ggProvider);

    const collectionRef = collection(db, "Account");
    const payload = {
      displayName: user.displayName,
      email: user.email,
      photoUrl: user.photoURL,
      uid: user.uid,
    };
    await addDoc(collectionRef, payload);
  };
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You're looking for the UserInfo.providerId field of the User object.

Something like this:

onAuthStateChanged(auth, (user) => {
  if (user) {
    // User is signed in, see docs for a list of available properties
    // https://firebase.google.com/docs/reference/js/firebase.User
    const uid = user.uid;

    // Show the provider(s) that the user is signed in with
    user.providerData.forEach((userInfo) => { // 👈
      console.log(userInfo.providerId);       // 👈
    })

    // ...
  }
});

You need the loop, since a user can be signed in with multiple providers at the same time. The provider string for Google is google.com (source).

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