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

306
Visualizações
Firebase V9 addDoc not returning success or failiure or writing to database

Auth related functions work, but with firestore I cant get anything to happen. No errors no successes returned by try catch. I have created the firestore in the firebase console, The created accounts show successfully from auth, but I just can't get anything to happen in firestore database

export const myApp = initializeApp(firebaseConfig);
// firebase.firestore().settings({ experimentalForceLongPolling: true });

export const db = getFirestore(myApp);
export const auth = getAuth(myApp);
export const logout = signOut;

// const dbInstance = collection(database, 'users');

export const addUser = async () => {
  try {
    console.log("Firing add function");
    const docRef = await addDoc(collection(db, "users"), {
      first: "Ada",
      last: "Lovelace",
      born: 1815,
    });
    console.log("Document written with ID: ", docRef);
    // console.log("Document written with ID: ", docRef.id);
  } catch (e) {
    console.error("Error adding document: ", e);
  }
};

I only get "Firing add function" then nothing. No errors or anything.

If i remove the await and then console docRef instead of docRef.id, then I get "Document written with ID: " and a Promise in a pending state.

Edit: I tried to use getDocs

export const getUsers = async () => {
  console.log("Getting users")
  const querySnapshot = await getDocs(collection(db, "users"));
  querySnapshot.forEach((doc) => {
    // doc.data() is never undefined for query doc snapshots
    console.log(doc.id, " => ", doc.data());
  });
  console.log("After get users")
};

@firebase/firestore: Firestore (9.6.11): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=not-found]: The project undefined does not exist or it does not contain an active Cloud Datastore or Cloud Firestore database. Please visit http://console.cloud.google.com to create a project or https://console.cloud.google.com/datastore/setup?project=undefined to add a Cloud Datastore or Cloud Firestore database. Note that Cloud Datastore or Cloud Firestore always have an associated App Engine app and this app must not be disabled. This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

But I go to my console and my Firestore is here and has one collection and one document that i made here from console

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Embarrassing, I console logged my firebaseConfig object and realized my FIREBASE_PROJECT_ID was undefined, I looked into my env file and realized it was not capitalized, so my firebase requests just couldn't find my firestore.

I would have not thought to look here since my auth related functions were working perfectly, but I guess auth related functions didn't need project ID to work so I never caught the misspell

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