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

153
Visualizações
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 Respostas
Responde à pergunta

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