Athar Shah
Athar Shah

Reputation: 11

How can we allow a particular User UID to have only access to a particular collection in Firestore security rules?

I would like to explain my problem with an example ;There is a user having uid [let say: vluAZiiV3deiFaPq5KdzFI1Dsx73] should only be given access to a collection [let say: elephant] out of three collections elephant,tiger,cheetah.

I tried to write the following rule to best of my knowledge but It didn't work.

service cloud.firestore {
  match /databases/{database}/documents {
    match /elephant/{document=**} {
      allow read, write: if request.auth.uid == AZiiV3deiFaPq5KdzFI1Dsx73
    }
 }}

Upvotes: 0

Views: 100

Answers (1)

Renaud Tarnec
Renaud Tarnec

Reputation: 83103

You should declare the uid value as string, with quotes, as follows:

service cloud.firestore {
  match /databases/{database}/documents {
    match /elephant/{document=**} {
      allow read, write: if request.auth.uid == "AZiiV3deiFaPq5KdzFI1Dsx73"
    }
 }}

Upvotes: 1

Related Questions