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

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

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