Dear Firebase Support Team,
I am encountering a persistent permission error in my Firestore database, specifically when attempting to read from the /reviews collection. This issue is strictly observed in our production environment and does not reproduce in local development or when using the Firebase Emulator.
Problem Description: When an authenticated user with the role: "admin" (as stored in their /user_profiles/{uid} document) tries to access the /reviews collection, they receive the following error: Error [FirebaseError]: Missing or insufficient permissions.
This error occurs when navigating to a page in my application that attempts to fetch data from the /reviews collection in production .
Relevant Firestore Security Rules:
For /reviews collection:
match /reviews/{reviewId} {
allow read: if isContributorOrMore();
// … other rules
}
For /user_profiles collection:
match /user_profiles/{uid} {
// …
allow read: if isSignedIn();
// …
}
Helper functions:
function isSignedIn() {
return request.auth != null;
}
function isContributorOrMore() {
return isSignedIn() && userProfile().data.role in [‘admin’, ‘ambassador’, ‘contributor’];
}
Steps Taken and Observations:
-
Firestore Data Verification: I have confirmed that the user’s
user_profiles/{uid}document in the live production Firestore database explicitly containsrole: "admin". -
Firebase Emulator Test: When I simulate a
GETrequest to/reviews/{reviewId}with the UID of the ‘admin’ user in the Firebase Emulator, the request succeeds without any permission issues . This strongly suggests that the security rules themselves are correctly configured to allow ‘admin’ users to read the collection. -
Client-Side Authentication State: My web application maintains a
firebaseSessioncookie (example:{"uid":"aoUI5txRMbaLLAwr6Wo8jpJ5KqV2","email":"ady@admin.com","role":"admin"}) indicating the user’s logged-in status and role. However, despite this, the Firestore SDK appears to not be correctly recognizing the authenticated user’s context, leading torequest.authpotentially beingnullor insufficient in the security rules evaluation when the request originates from the client in production .
Expected Behavior: An authenticated user with the admin role should be able to successfully read data from the /reviews collection in all environments, including production, according to the defined Firestore security rules.
I suspect the issue might be related to how the client-side Firebase Authentication state is being communicated or maintained with the Firestore SDK for subsequent database requests in the production environment, especially after initial login or a page refresh, as the rules themselves appear to be correct.
Could you please assist me in diagnosing why Missing or insufficient permissions is occurring for an ‘admin’ user on the /reviews collection exclusively in production , despite the rules appearing correct and emulator tests passing?
Thank you for your time and assistance.
I’m a citizen developer using firebase studio to develop web apps.
Sincerely,
Ady