Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=permission-denied]

Viewed 1467

I am getting the following error: Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=permission-denied]: Permission denied on resource project disneyplus-clone-a33d5.

I am learning React and the tutorial I am learning from uses firebase. I have very little knowledge about firebase. I cannot find any solution for this error. here is my fbconfig.js :

import { initializeApp } from 'firebase/app';
import { getAuth, GoogleAuthProvider } from "firebase/auth";
import { getStorage } from "firebase/storage";
import { getFirestore } from "firebase/firestore"

const firebaseConfig = {
  apiKey: "---",
  authDomain: "--.firebaseapp.com",
  projectId: "--",
  storageBucket: "--",
  messagingSenderId: "--",
  appId: "--",
  measurementId: "---",
};

const firebaseApp = initializeApp(firebaseConfig);
const db = getFirestore(firebaseApp);
const auth = getAuth();
const provider = new GoogleAuthProvider();
const storage = getStorage(firebaseApp);

export { auth, provider, storage };
export default db;

Here is my Home.js :

import db from '../fbconfig'
import { doc, onSnapshot, collection, query, where } from "firebase/firestore";

function Home() {

    useEffect(() => {
        const q = query(collection(db, "movies"))
        const unsub = onSnapshot(q, (snapshot)=>{
            let tempMovies = snapshot.docs.map((doc)=>{
                console.log(doc.data());
                return { id: doc.id, ...doc.data() }
            })
        });
1 Answers

code=permission-denied when working with Firestore is always a permissions problem on the collection you are trying to read, in this case "movies". To set permissions on a collection you can use the Firebase web gui or the command line tools.

The specific rule you will need for read access to "movies" is

match /movies {
      allow get: if true;
      allow list: if true;

      allow update: if false;
      allow create: if false;
      allow delete: if false;
    }

https://firebase.google.com/docs/rules/manage-deploy

Or the web ui

Related