Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Error : Firestore: The caller does not have permission to execute the specified operation. But I have already signed in

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

like image 286
Kakata Kyun Avatar asked Feb 01 '19 12:02

Kakata Kyun


3 Answers

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

change to this

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
 match /{document=**} {
  allow read, write: if request.auth != null;
  }
 }
}
like image 95
saigopi.me Avatar answered Nov 03 '22 18:11

saigopi.me


This is an issue because of the rules that your DB currently has. Please check both datebases, Realtime and Firestore.

As in general, having full security rules or any other rule that is not complitely understood by RD or CF logic will get you that error everytime.

> // Full security
> 
> {   "rules": {
>     ".read": false,
>     ".write": false   } }

in Firestore you can configurate that as the following:

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

For more examples you can see: https://gist.github.com/codediodeio/6dbce1305b9556c2136492522e2100f6 https://firebase.google.com/docs/database/security

like image 33
Jorge Cirilo Avatar answered Nov 03 '22 18:11

Jorge Cirilo


If you don't use authentication inside your app and only used the Firebase Firestore. So you can change it simply like this.

Change This

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

Into This

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

And last don't forget to publish these changes in order to save it.

If you have specified through timeStamp

If you have specified your Firestore rules through timeStamp then simply increase the length of duration of time.

rules_version = '2';
service cloud.firestore {
 match /databases/{database}/documents {
 match /{document=**} {
  allow read, write: if
    request.time < timestamp.date(2023, 3, 14);;
   }
  }
 }

Note: It is just for practicing and playing with Firestore data. If you want to build a production-level app then be sure to securely define your Firestore rules.

like image 5
Abdur Rehman Avatar answered Nov 03 '22 19:11

Abdur Rehman