我用一个非常简单的代码从firestore获取数据
import firebase from 'firebase/app';
import 'firebase/firestore'
const firebaseApp = firebase.initializeApp({
apiKey: "...",
authDomain: "...",
....
});
const db = firebaseApp.firestore();
export default db;
但我一直收到这个错误
[2021-06-05T00:58:41.274Z] @firebase/firestore: Firestore (8.6.5): Could not reach Cloud Firestore backend. Connection failed 1 times.
Most recent error: FirebaseError: [code=permission-denied]:
Permission denied on resource project.
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.
1.我有一个非常快的网络连接
1.我的时钟也与标准时间同步
我不知道为什么会这样?
请有人帮帮我!2!3!
5条答案
按热度按时间mspsb9vt1#
我也遇到了同样的问题,连接在某些环境下可以正常工作,但在我客户的公司网络上却不行。
在互联网上做了很长时间的研究后,我发现an issue on Github在谈论它。
以下是对我有效的方法:
这里我使用的是firebase v9。对于firebase v8,它类似于:
kadbb4592#
我能够通过直接使用我的凭据来解决这个问题,在那里我初始化了我的firebase配置,我以前是从我的env文件调用它们的,我认为我的应用程序之前没有获得env
2hh7jdfx3#
确保您的环境指向真正的Firestone数据库,而不是Firestore仿真器。当我遇到同样的问题时,这就是原因。
我使用的是Angular框架,所以我必须在app.module.ts文件中注解掉这些环境引用。
u1ehiz5o4#
我在使用angular fire时也遇到过这个问题。我所做的改变是将firestore设置添加到应用程序模块的提供者中:
根据GitHub issues的讨论,我认为你可以先试试
experimentalAutoDetectLongPolling
。除了使用非常旧的浏览器版本的用户之外,useFetchStreams
选项是不必要的。并且可以使用mitmproxy来重现firebase错误。
to94eoyn5#
我遇到了同样的问题,并尝试使用@atunde arisekola方法。如果您可以通过在
firebaseConfig
变量中使用直接凭证来解决这个问题,请考虑检查您使用的.env.local
或任何其他.env
是否位于根目录中。在我的例子中,firebaseConfig.ts
和.env.local
位于同一目录中。因此发生错误。建议在应用程序的根目录中设置.env
。