9

I am getting (on Android):

com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions

using these security rules:

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

My app seems to be properly authenticated using FirebaseAuth, as the mFirebaseAuth.getCurrentUser().getUid() returns the proper user ID.

Is there something I am doing wrong?

Daniele B
  • 19,801
  • 29
  • 115
  • 173
  • 1
    It's happening to me too. Until yesterday everything worked find, but since today it keeps returning permission error. I checked my security rules, and nothing is wrong. The weird behavior is it works sometimes, and it doesn't work sometimes with exactly same code. Did u fix the problem? – wonsuc Nov 12 '17 at 19:04
  • This is happening occasionally on web and react-native(firebase-ios-sdk) as well. The problem should be in firestore and not on the client sdk. – sowdri Nov 12 '17 at 21:34
  • Still having the same problem, have you managed to resolve it? – Limun Nov 02 '22 at 13:28

3 Answers3

3

Edit: just want to say that I managed to fix the issue by downgrading to 4.6.2. I have more details in this post

Pre-edit: This is happening to me ever since I upgraded react native and I cannot for the life of me figure out the problem. I've debugged it and my user is definitely authenticated at the time of the request, I checked this by running the below and I have a uid in there

firebase.auth().currentUser

So the next thing I wanted to do was check the session in the actual request to see what was happening. I added a piece of code to the entry point of my react app

XMLHttpRequest = GLOBAL.originalXMLHttpRequest ?
GLOBAL.originalXMLHttpRequest :
GLOBAL.XMLHttpRequest

and when I run this code it magically works again. This is delegating requests through the browser though so probably not a true test.

So then I started up Charles and compared the requests for my new react-native build with my old [working] react-native build. The requests look the same to me though (apart from a different sessionId) so I have no idea. The frustrating thing is the lack of debug tools through the firestore console.

My gut is to say some of the auth headers are expired/cached and that it's not firestore. Banging my head against a table at this point

JamesR
  • 950
  • 1
  • 7
  • 17
  • Using `firebase@4.6.2` worked for me as well. Thank you, never would have figured this out – Mingwei Samuel Mar 16 '18 at 19:57
  • Hi there, I was wondering if you'd be able to shed light on this matter. Looks like I've got it too in both react js and native. https://stackoverflow.com/questions/50929366/cloud-firestore-reactjs-error-missing-or-insufficient-permissions – Michael Jun 20 '18 at 14:41
1

It seem it's a Firestore problem (in beta today), not in the client side.

Jéwôm'
  • 3,753
  • 5
  • 40
  • 73
  • Still having this issue (occasional Missing or insufficient permissions), with Android SDK updated. Do you think this issue has still not been resolved by Firestore ? – François MARTIN Jul 17 '18 at 13:06
  • I am using Firestore in a small Angular 6 project and I still have the same problem as I write. – Joel Azevedo Aug 20 '18 at 16:29
1

I asked the Firebase support team directly since this issue was kind of critical for our service and I received the email below. It seems they fixed the bug now.

Please let me know if the issue happens again.

Hi there,

We have just confirmed with our engineers that this sporadic issue with our Security Rules for Firestore was a known bug but was already fixed today. Kindly test your security rules again and let us know if you are still encountering the issue.

Regards, Kevin

wonsuc
  • 3,498
  • 1
  • 27
  • 30
  • I'm having this problem now. I was able to submit data this morning - now I'm not. I didn't change anything and am getting this permissions error. I'm well within my usage limits – Mel May 19 '19 at 11:08