Firestore keep denying requests: FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.

26,210 views
Skip to first unread message

Prateek Rai

unread,
Jul 18, 2022, 10:16:32 AM7/18/22
to Firebase Google Group
Hi,
Every-time I open the app, I'm getting the same issue repetitively. 
FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.

Exception is saying, authentication is not done, but it's not true. User can login my app either through Google login or Anonymous user that is provided by Firebase.

Everything is working fine from past 3 month. This issue arrises automatically 3 days back and I raised query to Firebase support team but they not responded yet.

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


This is rule I have added. But I don't know why it is not working! All of my development has stopped due to this.

Please help me in this.

P.S - I'm scared after this issue that if I can use Firebase in my next production app or not.

Stephan Strecker

unread,
Jul 18, 2022, 5:23:16 PM7/18/22
to fireba...@googlegroups.com
Sry I don't know your code. 
Probably you can debug it by yourself

First remove all rules and check if you get access to the database. 

If this works use the simulator to define the right rules. We are using the rules extremely in our app and have no problems there at all. 

If this will not help I think you need to share some code 🤗

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/bcd278b4-79a9-4ffc-a630-ce9547a9b74fn%40googlegroups.com.

Prateek Rai

unread,
Jul 18, 2022, 11:47:55 PM7/18/22
to Firebase Google Group
Hi Stephan,
After removing all rules, I'm able to get access to database. But after applying rules, Exception is coming. 
I'm building MCVE today, and will share the repo link. 

I debug the code from last 5 days. And one thing more same code is working for production app that is LIVE on PlayStore.

Thanks!

M C

unread,
Jul 19, 2022, 10:40:52 AM7/19/22
to fireba...@googlegroups.com
Hello
Prateek Rai, check your app's API permissions on Google Cloud. If your app doesn't have App Check, add App Check to the app. I don't think Auth is having problems because of Firebse rules. I guess, you are having a problem especially because of Google Cloud.



You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

Prateek Rai

unread,
Jul 19, 2022, 6:14:21 PM7/19/22
to Firebase Google Group
Hi, I checked Google Cloud everything looks fine. And I already enabled App check. I disabled it and enabled it but issue is still there. I don't know how and why this issue arrises?

Samuel Akabo

unread,
Jul 19, 2022, 6:14:21 PM7/19/22
to fireba...@googlegroups.com
Hi Prateek,

replace if request.auth != null with if request.auth.uid != null. I remember experiencing a similar issue in the past and that worked for me.

M C

unread,
Jul 20, 2022, 11:05:10 AM7/20/22
to fireba...@googlegroups.com
Prateek, I want to make a suggestion to you. Create a new app from your Firebase account. Add Auth to this application. If you do not have a registration problem in this application, there is no problem with your Firebase account. If there is no problem with your Firebase account, create a new API key over Google Cloud for the application you are having problems with. Add this key to app, redownload Firebase Json and add it to your app. I hope this method helps you

20 Tem 2022 Çar 01:14 tarihinde Samuel Akabo <super...@gmail.com> şunu yazdı:

Bristlepath S

unread,
Jul 20, 2022, 11:34:41 PM7/20/22
to Firebase Google Group
Could you be exceeding the limit which gives you Permission denied? See the limits here:
https://firebase.google.com/docs/firestore/security/rules-structure#version-2
Look for section on Security rule limits.
Myself, I'd write a granular rule just to see if it worked.  The debugging tools they give you pinpoint the failure very well in both the console and the emulator.  Have you looked at the rules output and the log files? 

Prateek Rai

unread,
Jul 29, 2022, 10:46:14 AM7/29/22
to Firebase Google Group
Hi guys,
From last few days, I'm following all your suggestions. Unfortunately none of them works. But this time I figure out why not working any thing.

As soon as, I'm sign in through Google account data is loaded first but on making another request, I'm getting FirebaseAuth exception that is 
FirebaseAuth: Notifying auth state listeners about a sign-out event.
FirebaseAuth: notifying id token listeners about a sign-out event.

And after this debug message it get signed out and that's why I'm getting PERMISSION_DENIED: Missing or insufficient permissions.

I don't know why automatically logged out after first data load. I go through my entire codebase to see if at any point I'm calling logout, and there is no logout kind of method I'm calling. I also stopped logout method from the entire application to debug this issue. But I'm not able to figure out how to get rid of this bug.
If anyone go through similar issue please help me.

Thanks

Bristlepath S

unread,
Jul 30, 2022, 4:47:42 PM7/30/22
to Firebase Google Group
If it thinks you've signed out, you are going to have to sign in again. I assume you have code to update tokens when app starts up.  Based on your firestore rule, the missing permissions is a valid error when there is no user that is signed in. Sounds like you've been working on the wrong "problem".
I'd execute a sign-out in your code to make sure your code is in sync with what Firebase thinks happened. That should then trigger a sign-in in your code. And an update to your token.
I'd also fix your code so that its listeners are responding to the sign-out event sent by Firebase. Just because *YOU* don't think it is happening doesn't mean it is not. :-)
The user can sign-out via their google accounts from multiple apps.

nitroplr

unread,
May 7, 2023, 5:48:30 PM5/7/23
to Firebase Google Group
I just ran into this with my app this post was a life saver.  For whatever reason only new accounts would get missing or insufficient permissions even though they had definitely verified their email when using if request.auth != null.  If request.auth.id != null fixed it.  Very strange, the auth has worked fine for a couple years now and I haven't changed how I'm creating accounts or logging in.
Reply all
Reply to author
Forward
0 new messages