由于访问控制检查,XMLHttpRequest无法加载https://firestore.googleapis ..... [英] XMLHttpRequest cannot load https://firestore.googleapis..... due to access control checks

查看:1693
本文介绍了由于访问控制检查,XMLHttpRequest无法加载https://firestore.googleapis .....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的项目中实现firestore。
我现在正在做的只是实现它并读取一些数据,但我在标题中得到错误:

I'm trying to implement firestore in my project. What I'm doing right now is just implementing it and read some data, but I get the error in the title :

XMLHttpRequest无法加载 https://firestore.googleapis.com/google.firestore .....由于访问控制检查。

XMLHttpRequest cannot load https://firestore.googleapis.com/google.firestore..... due to access control checks.

我使用以下内容:

// 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);
        });

我尝试检索数据的部分导致错误(docRef.get()... )

The part where I try to retrieve the data cause the error (docRef.get()...)

你知道为什么会发生这个错误吗?

Do you have an idea why is this error happening ?

提前致谢,

推荐答案

听起来您需要更新Firestore安全规则。您可以通过Firebase控制台网站中数据库页面的规则标签执行此操作。

Sounds like you need to update your Firestore Security Rules. You can do this via the "Rules" tab of the Database page in the Firebase Console website.

有关Firestore规则的文档位于: https://firebase.google.com/docs/firestore/security/get-started

Docs about Firestore Rules are here: https://firebase.google.com/docs/firestore/security/get-started

您可以使用此规则集使任何人都可以访问它。我会使用这些规则来确保您能够解决问题。之后,我会调整您的规则,使其符合您的应用数据所需的安全性(或敏感度)。

You can use this ruleset to make it accessible to anyone. I would use these rules just to make sure that you were able to fix your problem. After that, I would tweak your rules so they match the amount of security (or sensitivity) your app's data needs.

service cloud.firestore {
match / databases / {database} / documents {
match / {document = **} {
allow read,write:if true;
}
}
}

这篇关于由于访问控制检查,XMLHttpRequest无法加载https://firestore.googleapis .....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆