【问题标题】:@firebase/firestore: Firestore (8.6.5): Could not reach Cloud Firestore backend@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端
【发布时间】:2021-08-23 08:38:24
【问题描述】:

我以前使用过 expo,但我退出了我的项目,并且一切正常,期待我的 firebase 连接。它说:@firebase/firestore:Firestore (8.6.5):无法访问 Cloud Firestore 后端。后端在 10 秒内没有响应。

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

const firebaseApp = firebase.initializeApp({
  apiKey: 'AIzaSyALTdavPNQReVJNWyc2aF8DfexzxzDoXB0',
  authDomain: 'projetofinal-e1147.firebaseapp.com',
  projectId: 'projetofinal-e1147',
  storageBucket: 'projetofinal-e1147.appspot.com',
  messagingSenderId: '546669005614',
  appId: '1:546669005614:web:1b06c375565e04b4c888bf',
  measurementId: 'G-KLJBEWBR3S',
});

class Fire {
  constructor(callback) {
    this.init(callback);
  }

  init(callback) {
    if (!firebase.apps.length) {
      firebase.initializeApp(firebaseConfig);
    }

    firebase.auth().onAuthStateChanged(user => {
      if (user) {
        callback(null, user);
      } else {
        firebase
          .auth()
          .signInAnonymously()
          .catch(error => {
            callback(error);
          });
      }
    });
  }

  getLists(callback) {
    let ref = this.ref.orderBy('color');

    this.unsubscribe = ref.onSnapshot(snapshot => {
      lists = [];

      snapshot.forEach(doc => {
        lists.push({id: doc.id, ...doc.data()});
      });

      callback(lists);
    });
  }

  addList(list) {
    let ref = this.ref;

    ref.add(list);
  }

  deleteList(list) {
    let ref = this.ref;

    ref.doc(list.id).delete();
  }

  updateList(list) {
    let ref = this.ref;

    ref.doc(list.id).update(list);
  }

  get userId() {
    return firebase.auth().currentUser.uid;
  }

  get ref() {
    return firebase
      .firestore()
      .collection('users')
      .doc(this.userId)
      .collection('lists');
  }

  detach() {
    this.unsubscribe();
  }
}

export default Fire;

这是我的 Firebase 文件,它在我的 expo 应用程序中运行,但现在不再可用。

【问题讨论】:

    标签: javascript android firebase react-native react-native-android


    【解决方案1】:

    添加这个:

    if (!firebase.apps.length) {
          firebase.initializeApp(firebaseConfig);
        + firebase.firestore().settings({ experimentalForceLongPolling: true, merge: true });
        }
    

    【讨论】:

    • 请您的回答更具描述性。例如:为什么这段代码会起作用?另外,让 OP 知道在哪里添加它。
    猜你喜欢
    • 2021-08-13
    • 2018-11-13
    • 1970-01-01
    • 2022-08-04
    • 2019-02-07
    • 2020-09-29
    • 2018-09-15
    • 2018-11-03
    相关资源
    最近更新 更多