2020
09.17

 

1. 'user_id'라는 필드의 값이 요청하는 사용자의 uid와 일치할경우 쓰기 허용

https://firebase.google.com/docs/firestore/security/secure-data?hl=ko#the_resource_variable

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
  
    //match /{document=**} {
    //  allow read, write: if false;
    //}
    
    match /userData/{document} {
      allow read: if request.auth.uid != null;
      allow create: if request.auth.uid == request.resource.data.user_id;
      allow update, delete: if request.auth.uid == resource.data.user_uid;
    }
  }
}

 

2. 문서의 id가 uid로 지정하는경우 : uid와 document id가 일치할경우 허용

https://firebase.google.com/docs/firestore/security/secure-data?hl=ko#using_variables_from_wildcards

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
  
    //match /{document=**} {
    //  allow read, write: if false;
    //}
    
    match /userData/{userIDFromWildcard} {
      allow read: if request.auth.uid != null;
      allow create: if request.auth.uid == userIDFromWildcard;
      allow update, delete: if request.auth.uid == userIDFromWildcard;
    }
  }
}

 

COMMENT