简体   繁体   中英

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
    }
 }}

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"
    }
 }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM