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

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

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