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

163
Visualizações
Create Firestore document only the first time a user signs in with google oAuth

I'm new to react and firebase and was trying to create a firestore document only during the creation of user.

Its working fine on the local provider as there sign in and sign up are two different things but when it comes to google o Auth both the options use same function.

So how do i create my initial documnet during creation of user via google o Auth as it just resets my entire document when i log out and log in back.

googleAuth function

    function googleAuth(provider) {

        return firebase
            .auth()
            .signInWithPopup(provider)
            .then(async function createUserDb(userCredentials) {
                await setDoc(doc(db, "users", userCredentials.user.uid), {myList: []},{ merge: true })
                })
    }

sign up and sign in functions

    function signUp(email, password) {
        return auth.createUserWithEmailAndPassword(email, password).then(
            async function createUserDb(userCredentials) {
                console.log(userCredentials.user.uid);
                await setDoc(doc(db, "users", userCredentials.user.uid), {myList: []})
    })
    }

    function signIn(email, password) {
        return auth.signInWithEmailAndPassword(email, password)
    }

my firestore users collection when a new user is created (google auth user here)

firestore user collection

it should save the data even after sign in (local auth user here)

enter image description here

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

0

after scraping through some posts found .additionalUserInfo.isNewUser method which checks if the user has created new account or is already a user which fixed my issue.

Thank you for any help that you guys provided.

    function googleAuth(provider) {

        return firebase
            .auth()
            .signInWithPopup(provider)
            .then(async function createUserDb(userCredentials) {
                if(userCredentials.additionalUserInfo.isNewUser) {
                    await setDoc(doc(db, "users", userCredentials.user.uid), {myList: []},{ merge: true })
                } 
                })
    }
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