0
votes

Having issues saving to firestore and subsequently retrieving that data. Below is a sample of the code that's failing. This code is pretty basic and my internet connection is fine. Upgrading to websdk 5.0.4 does not resolve issue either.

save = async (data: any) => {
    try {
      const { id, ...rest } = data;
      await db
        .collection('/customers')
        .doc(id)
        .set({ ...rest });

      const saved = await db
        .collection('/customers')
        .doc(data.id)
        .get();
      console.log(saved.data());
    } catch (error) {
      console.log(error);
    }
  };

In debug mode I see the following:

[2018-05-28T13:09:19.910Z] @firebase/firestore: Firestore (5.0.3) [PersistentStream]: close with error: FirebaseError: [code=unknown]: Fetching auth token failed: Cannot redefine property: _lat index.esm.js:65 [2018-05-28T13:09:19.915Z] @firebase/firestore: Firestore (5.0.3) [ExponentialBackoff]: Backing off for 46014.29558926278 ms (base delay: 60000 ms) index.esm.js:65 [2018-05-28T13:10:06.122Z] @firebase/firestore: Firestore (5.0.3) [PersistentStream]: close with error: FirebaseError: [code=unknown]: Fetching auth token failed: Cannot redefine property: _lat

1
Two things I would check first - 1. What's inside data? maybe that object contains things with types that cannot be persisted to Firestore? 2. What are the security rules you have in place? - Ohad
@Ohad. data is a simple object {name: '...', number: '...'}. What's even stranger is that realtime db is fine, auth is fine. Nothing in the config is different for the other services - Felix

1 Answers

0
votes

A simple example for insering data in firestore DB and check responses:

  //---creating reference--- 
  const customRef = this.db.collection('customers');

  //---inserting in DB---
  customRef.set({
    name: 'someName',
    status: true,
  }).then(response => {
    console.error('response: ', response);
  })
    .catch(function (error) {
      console.error('Error: ', error);
    });

check too, if RULES in firebase console database are configured for tests:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}