React-native-firebase: Get Error : Firestore: The caller does not have permission to execute the specified operation. (firestore/permission-denied). But I have already signed in

Created on 1 Feb 2019  路  7Comments  路  Source: invertase/react-native-firebase


I have this problem and try to fix with all solutions I had found,but still not works. My rules in firebase cloud firestore is :

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

And I had already enable Sign-in Method Anonymously.

Android

android/build.gradle:

        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:4.0.1'

android/app/build.gradle:

    compile project(':react-native-firebase')
    compile project(':react-native-fbsdk')
    implementation project(':react-native-firebase')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules

    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation 'com.google.firebase:firebase-auth:16.0.4'
    implementation 'com.google.firebase:firebase-firestore:17.1.0'

Testing.js:

firebase.auth().signInAnonymously().then(()=>{
        firebase.app().firestore().collection('Hello').doc('hello').set({
          id:'fadsa'
        }).catch((err)=>{
          alert(err);
        })
      })

Environment

  • Platform that you're experiencing the issue on:

    • [ ] iOS

    • [x] Android

  • Operating System:

    • [x] Windows, version: N/A

  • Firebase module(s) you're using that has the issue:

    • [x] Authentication

    • [x] Cloud Firestore




Think react-native-firebase is great? Please consider supporting the project with any of the below:

Most helpful comment

Thank you @Ehesp I solved this problem. I had changed the rule :
allow read, write: if request.auth.uid != null;
Instead of:
allow read, write : if auth != null ;

All 7 comments

Could you try removing the app part on the firestore call, it'd be interesting to see whether that's impacting it.

P.S. Chain your promise calls to ensure all errors are captured:

firebase.auth().signInAnonymously()
    .then(()=> {
        return firebase.firestore().collection('Hello').doc('hello').set({
              id:'fadsa'
        });
    }).catch((err)=>{
        alert(err);
    })

Could you try removing the app part on the firestore call, it'd be interesting to see whether that's impacting it.

P.S. Chain your promise calls to ensure all errors are captured:

firebase.auth().signInAnonymously()
  .then(()=> {
      return firebase.firestore().collection('Hello').doc('hello').set({
            id:'fadsa'
      });
  }).catch((err)=>{
      alert(err);
  })

I tried. But it not works. It captured this error:
Error: Firestore: The caller does not have permission to execute the specified operation.(firestore/permission-denied)

@Ehesp If I remove the rule of console firebase , It works. But I want to secure my data so that I force it must login to change the data and read data. It doesn't work. Seem something wrong with firebase. Not my code. Hmm

For further info, I tried testing simulator in cloud firestore console. I had this error:
https://trello-attachments.s3.amazonaws.com/5b19f59752aad8504ff9e26c/5c590716ed711938a367dbcd/bd5c8bf88d04a1b7203e7ed31fd880b2/Capture.PNG

Thank you @Ehesp I solved this problem. I had changed the rule :
allow read, write: if request.auth.uid != null;
Instead of:
allow read, write : if auth != null ;

@kyunkakata are you sure it is secure? ie. is auth not null when user is not logged in?

@pie6k auth not null means user is logged-in, as if user is logged-in it has any uid instead of null.

Was this page helpful?
0 / 5 - 0 ratings