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

294
Views
Firebase store an user into database after signup with a custom document name (Firebase v9)

Is there any way to store an user inside firebase database but with custom document name. What I am trying to achieve is that after the user signs up to the app, the app saves their details into a firebase database.

Here is my code:

function signUp(email, password) {
    return createUserWithEmailAndPassword(auth, email, password).then(() => {
      addDoc(usersCollectionRef, auth.currentUser.uid,{
        email: email,
        password: password,
        id: auth.currentUser.uid,
        role: "user",
      });
    });
  }

As you can see I'm trying to save the document name like this: auth.currentUser.uid, which I put as the second parameter of addDoc function, but I get this error:

Function addDoc() called with invalid data. Data must be an object, but it was: "B0P4tBzY2uOF2XG2o6cT..." (found in document users/Gmbv7Zd2JZF4PtTct4VF)

Does anyone know how to do this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

addDoc will always generate a new random document ID. If you want to specify your own document ID, don't use addDoc. Instead, follow the instructions in the documentation and build a reference to the document to create, then create it with setDoc:

import { doc, setDoc } from "firebase/firestore"; 


setDoc(doc(usersCollectionRef, auth.currentUser.uid), {
    email: email,
    password: password,
    id: auth.currentUser.uid,
    role: "user",
});
about 4 years ago · Juan Pablo Isaza 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!