Gio*_*Gio 7 javascript firebase google-cloud-firestore
我正在尝试在我的项目中实现Firestore。我现在正在做的只是实现它并读取一些数据,但是标题中出现错误:
由于访问控制检查,XMLHttpRequest无法加载https ://firestore.googleapis.com/google.firestore.....。
我使用以下内容:
// Initialize Firebase
var config = {
apiKey: "xxx",
authDomain: "xxx",
databaseURL: "xxx",
projectId: "xxx",
storageBucket: "xxx",
messagingSenderId: "xxx"
};
firebase.initializeApp(config);
// Initialize Cloud Firestore through Firebase
var db = firebase.firestore();
var docRef = db.collection("users");
docRef.get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
//alert(doc.data().born);
});
})
.catch(function(error) {
console.log("Error getting documents: ", error);
});
Run Code Online (Sandbox Code Playgroud)
我尝试检索数据的部分导致错误(docRef.get()...)
您知道为什么会发生此错误吗?
提前致谢,
听起来您需要更新 Firestore 安全规则。您可以通过 Firebase 控制台网站数据库页面的“规则”选项卡执行此操作。
有关 Firestore 规则的文档位于:https://firebase.google.com/docs/firestore/security/get-started
您可以使用此规则集使其可供任何人访问。我会使用这些规则只是为了确保您能够解决您的问题。之后,我会调整您的规则,使它们符合您的应用程序数据需求的安全性(或敏感性)。
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
归档时间: |
|
查看次数: |
1815 次 |
最近记录: |