Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!