2
votes

I was previously using firebase realtime database however now want to switch over to Cloud Firestore but am getting the below error, even when authenticated. I'm currently using Android Simulator, tried disabling my realtime database but cannot find a solution.

Firebase v5.4.2

[2018-09-02T12:53:42.064Z] @firebase/firestore:', 'Firestore (5.0.4): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds. 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.

My config is setup:

{
  "apiKey": "apiKey",
  "authDomain": "authDomain.firebaseapp.com",
  "databaseURL": "https://databaseURL.firebaseio.com",
  "projectId": "projectID",
  "storageBucket": "storageBucket.appspot.com",
  "messagingSenderId": "messagingSenderId"
}

As per docs I'm adding a users collection. Note that I do not get into the .then or the .catch statement even if I setup a users collection manually against the database.

onTestPress() {
    console.log("onTestPress");
    var db = firebase.firestore();
    //console.log(db);
    const settings = { timestampsInSnapshots: true };
    db.settings(settings);

    db.collection("users").add({
      first: "Ada",
      last: "Lovelace"
    }).then(function (docRef) {
      console.log("adding document: ", docRef.id);
    }).catch(function (error) {
      console.log("Error adding document: ", error);
    });

    db.collection("users").get().then((querySnapshot) => {
      console.log(`querySnapshot: ${querySnapshot}`)
      querySnapshot.forEach((doc) => {
        console.log(`${doc.id} => ${JSON.stringify(doc.data())}`);
      });
    });
  }

This is from Android Logcat you can see the .get() query returns the local copy. Only thing suspicious is the duplicate layer name?

09-02 14:05:37.811 2987-4016/com.myApp I/ReactNativeJS: onTestPress
    09-02 14:05:47.837 2987-4016/com.myApp E/ReactNativeJS: '[2018-09-02T13:05:47.837Z]  @firebase/firestore:', 'Firestore (5.0.4): Could not reach Cloud Firestore backend. Backend didn\'t respond within 10 seconds.\nThis 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.'
    09-02 14:05:47.849 2987-4016/com.myApp I/ReactNativeJS: querySnapshot: [object Object]
    09-02 14:05:47.849 2987-4016/com.myApp I/ReactNativeJS: 3jifIc5kyEkGU4Bzvau9 => {"first":"Ada","last":"Lovelace"}
    09-02 14:05:47.858 1431-1431/? D/SurfaceFlinger: duplicate layer name: changing com.myApp/com.myApp.MainActivity to com.myApp/com.myApp.MainActivity#1
    09-02 14:05:47.931 2987-3021/com.myApp D/EGL_emulation: eglMakeCurrent: 0x9d7857e0: ver 3 0 (tinfo 0x9d783540)

Here's my import:

import firebase from "firebase";
import '@firebase/firestore'

Rules setup which should allow read and write?

// Allow read/write access to all users under any conditions
// Warning: **NEVER** use this rule set in production; it allows
// anyone to overwrite your entire database.
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

I'm really not sure what else I can check so any advise would be greatly appreciated!

1
After doing a bit more digging I suspect the issue to be with: github.com/firebase/firebase-js-sdk/issues/… Once I take the plunge and upgrade RN to 0.55.0, will advice the outcome.Dereck
Updated to 0.55.0 and still having the same issue. Any advice would be appreciated.Dereck
After updating to 0.55.0 and upgrading all react-native-firebase modules everything is now working.Dereck

1 Answers

0
votes

I also had this issue. The warning should appear after 10 seconds. but in my case, it appears when i load the component, without timeout. because my laptop's time in not correct. I did correct time and still had that issue. so i had to turn on "Set time automatically" and "Set time zone automatically" in "Date & time" settings in windows. everything works out for me.