javascriptgoogle-cloud-firestorefirebase-authenticationfirebase-app-check

Phone Verfication Auth is not allowing to Access data in Firestore


I am facing issue with Getting Data from Firestore

Error : FirebaseError: Missing or insufficient permissions.

After changing the rule to below

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

Below is the Function from where i am trying to Call the database

async handelSearch(searchTerm: any) {

  onAuthStateChanged(this.auth, async (user) => {
    if (user) {
      // User is signed in, see the user's uid
      console.log(user.uid)
      const querySnapshot = await getDocs(q);
      let temp: any[] = []
      querySnapshot.forEach((doc) => {
        // doc.data() is never undefined for query doc snapshots
        temp.push(doc.data())
      });
      this.serachBarService.MemberList.update(() => temp);


      // Access and modify user data here
    } else {
      console.log("No auth")
      // User is signed out
    }
  });
}

I am successfully able to console log the User ID also Authentication seems working fine to me don't know what's missing while accessing the firestore.

I am working with Highly sensitive data here so can't run database in Test mode

UPDATE :

I tested this in Emulator, Rule is working correctly there enter image description here


Solution

  • I found the issue. App Check was enforced on Firestore. After disabling it, the problem was resolved. I'm unsure why App Check was blocking reads and writes

    However, I verified that my security rules were functioning correctly, allowing only authenticated users to read and write.