Today I noticed that I am unable to deploy my Firestore rules, even though they worked fine until now and I didn't change them. Here's an excerpt of the part it doesn't like:
match /databases/{database}/documents {
function userMatchesId(userId) {
return request.auth != null
&& request.auth.uid == userId
}
function userIsAdmin() {
return request.auth != null
&& get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == "admin"
}
// === Admins ====
// Admin users are allowed to access everythings.
// Writes should be performed via code executed by a service account
match /{document=**} {
allow read: if userIsAdmin()
}
// ==== Private ====
// Collections private to the user. Documents read access is matched
// with the authenticated user id.
match /users/{userId} {
allow get: if userMatchesId(userId)
}
match /userCredits/{userId} {
allow get: if userMatchesId(userId)
}
}
In practice these rules have worked as I imagined it. Admins are allowed to read from collections that non-admins are not able to query directly. However, now I get this error during deployment:
Error: Compilation error in firestore.rules:
[W] 42:5 - Overlapping recursive wildcard match statement.
I do not quite understand the issue here. How would you fix this?