【发布时间】:2019-11-20 22:04:04
【问题描述】:
我设置了一个使用 Firestore 数据库的 Firebase 项目。我获得了以下 sn-p 以在我的 Javascript 代码中使用它:
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
authDomain: "xxxxxxxxxx.firebaseapp.com",
databaseURL: "https://xxxxxxxxxxxxx.firebaseio.com",
projectId: "xxxxxxxx",
storageBucket: "xxxxxxxxx.appspot.com",
messagingSenderId: "xxxxxxxxx",
appId: "1:xxxxxxxxxxxxxxxxxxxxxxxxxxx"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
到那时,一切都在努力。然后,我需要通过在 firebase 项目以及 Google Cloud Platform 项目的“凭据”菜单中的 apiKey 上设置授权域来确保只有我的域可以使用该应用程序。
到目前为止,我的项目仍然有效,但我注意到它在任何域中仍然有效。所以限制不起作用。实际上,经过更多的测试,我发现 apiKey 甚至不是我的项目所必需的,我可以将 snipet 减少到以下内容并且仍然可以工作:
// Your web app's Firebase configuration
var firebaseConfig = {
projectId: "xxxxxxxx",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
所以我想知道:我的项目如何在仅给出 projectId 的情况下在 Firestore 数据库中运行和写入?我在 sn-p 中得到了一堆甚至没有必要的信息。
有谁知道为什么这会发生在我身上?我尝试创建一个新项目,再次遵循不同的教程,结果相同。实际上,我使用的其中一个教程具有相同的行为,因为我可以使用本教程的项目(它实际上是在线的),只需指定 projectId 并且我可以通过从我的本地服务器发送垃圾邮件来使其 Firestoere 配额用完。
我找不到任何关于我的类似案例的信息。请帮忙。
PS:如果重要的话,这是我的 Firestore 数据库规则:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
【问题讨论】:
-
您可能在 Firestore 规则中启用了公共读/写访问权限。我会检查的。 //编辑:感谢您更新问题。实际上,
allow read, write: if true;表示对 firestore 的公共读写访问权限。查看firebase.google.com/docs/firestore/security/get-started了解更多信息 -
@Goony 你能解决这个问题吗?我也有同样的问题。
标签: javascript firebase google-cloud-firestore api-key