ZUK*_*INI 1 firebase reactjs firebase-authentication firebase-realtime-database google-cloud-firestore
尝试从 Firestore 获取文档及其字段时,出现以下错误:
来自本地主机:
@firebase/firestore: Firestore (8.3.2): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=permission-denied]: Permission denied on resource project "xxxxxxxxx".
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.
Run Code Online (Sandbox Code Playgroud)
来自 Firebase 托管:
BrowserPollConnection.ts:728 GET https://[PROJECT_ID]-default-rtdb.firebaseio.com/.lp?start=t&ser=82934841&cb=1&v=5&p=1:303920306737:web:bc61250d7aa9a51a415310 net::ERR_NAME_NOT_RESOLVED
Run Code Online (Sandbox Code Playgroud)
当查找这个问题时,解决方案似乎是缓存、DNS、ISP、VPN 或类似的东西。我已经尝试了所有建议的解决方案,但仍然没有解决方案。我想这可能是我配置连接的方式?
我唯一觉得奇怪的是,它声明它试图访问https://[PROJECT_ID]-default-rtdb.firebaseio.com,我认为它仅适用于 RTDB,但我正在使用 Firestore。
在我的配置文件中,我有以下内容:
firebase/index.js
import firebase from 'firebase/app';
import 'firebase/firestore';
var config = {
apiKey: process.env.REACT_APP_API_KEY,
authDomain: `${process.env.REACT_APP_PROJECT_ID}.firebaseapp.com`,
projectId: process.env.REACT_APP_PROJECT_ID,
storageBucket: process.env.REACT_APP_STORAGE,
messagingSenderId:process.env.REACT_APP_MESSAGE_SENDER_ID,
appId:process.env.REACT_APP_APP_ID,
measurementId: process.env.REACT_APP_MEASUREMENT_ID
}
firebase.initializeApp(config);
export default firebase;
Run Code Online (Sandbox Code Playgroud)
我正在尝试仅获取useEffect
. 奇怪的是,一旦返回setData
,执行 data.id 会打印出实际的 ID,但是在useEffect
其内部或外部检查文档是否存在docSnapshot.exists
始终为 false。可能是因为我的连接问题。
import firebase from './firebase';
const db = firebase.firestore();
.
.
.
useEffect(() => {
db.collection('myCollection').doc('myDocID')
.onSnapshot(docSnapshot => {
console.log(`Received doc snapshot: ${docSnapshot}`);
setData(docSnapshot);
}, err => {
console.log(`Encountered error: ${err}`);
});
},[]);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1675 次 |
最近记录: |