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

157
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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