Access parent documents field in Firestore rules

后端 未结 3 655
小鲜肉
小鲜肉 2021-02-05 05:42

I\'m implementing a recipe book in Firestore where every user is able to see all the recipes all users created but only the original author of the recipe is allowed to edit or d

3条回答
  •  萌比男神i
    2021-02-05 06:07

    Dan's answer above works great! Just for reference, in my case I only needed the root parent document ID, you can use the variable from the match statement above the nested one, like this:

    service cloud.firestore {
      match /databases/{database}/documents {
    
        function isSignedIn() {
          return request.auth != null;
        }
    
        match /ListOfRecipes/{recipeID} {
            allow read, create: if isSignedIn();
            allow update, delete: if resource.data.creatorUID == request.auth.uid;
    
            match /List/{list} {
                allow read: if isSignedIn();
                allow write: if  recipeID == 'XXXXX';
            }
        }
      }
    }
    

提交回复
热议问题