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

154
Vistas
How to upload document whenever a user signs up in firebase with custom users uid?

I am working with react and firebase ver 9. As firebase offers limited field and I need to send some more data while registering a user. I saw that you can do this while uploading document whenever a user signs up. I have written the code for it but when I run it only users are registered but my document doesn`t get uploaded.

Here`s my code:

import { useState } from "react"
import { auth, db } from "../Authentication/firebaseConfig"
import { createUserWithEmailAndPassword } from "firebase/auth"
import {

    collection,
    setDoc,
    addDoc,doc
} from "firebase/firestore";


export const useSignup = () => {
    const [error, setError] = useState(null)


    const signup = async (email, password, displayName) => {
        setError(null)

        const current_user = await createUserWithEmailAndPassword(auth, email, password, displayName);
        const uid = current_user.user.uid;
        await addDoc(collection(db, "users"), {
            uid: uid,
            displayName,
            email,
        })
          .then((res) => {
            console.log('user signed up:', res.user)
        })
    .catch((err) => {
        setError(err.message)
    })
       
        
    }
    return { error, signup }
}
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

As stated by @Danial, the error was produced by Cloud Firestore Rules that is set to false.

Sample Rule:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
  }
}

Sample Firestore rule above will prohibit you to read and write to any collection and document. Changing it to true allows the public to read and write to Firestore.

about 4 years ago · Santiago Gelvez 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