Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 cannot load https://firestore.googleapis.com/google.firestore..... due to access control checks.

I use the following :

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

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

Do you have an idea why is this error happening ?

Thanks in advance,

like image 457
Gio Avatar asked Dec 15 '17 10:12

Gio


2 Answers

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.

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

like image 116
Mike McLin Avatar answered Oct 14 '22 12:10

Mike McLin


For anyone else with this same issue, it has been reported and the resolution is still in progress: https://github.com/firebase/firebase-js-sdk/issues/3708

Edit: Even though the thread in the link above wasn't resolved, it was closed. The issue still occurs for me.

like image 38
Jim Jimmity Avatar answered Oct 14 '22 13:10

Jim Jimmity