2017-12-24 21 views
0

나는 다음 경우 FireStore 규칙이 있습니다경우 FireStore : GET 경기에서 허가를-거부

service cloud.firestore { 
    match /databases/{database}/documents { 
    match /{usuarios=**} { 
     allow write: if get(/usuarios/$(request.auth.uid)).data.level == 0 || get(/usuarios/$(request.auth.uid)).level == 0; 
    } 
    } 
} 

내가 얻을이 "권한-거부"나는이 쿼리를 시도 할 때 :

firebase.firestore().collection('usuarios').doc(uid).set({...}); 

이 내 DB입니다 실제로 :

enter image description here

는 PD : 나는 그의 U에 의해 (내 DB에 새로운 사용자에 대한 정보를 추가 할 ID)

답변

2

get 요청에 따라 매우 비싸고 비효율적입니다. 대신 데이터베이스의 구조를 정의하는 것처럼 규칙을 작성해야합니다. 여기의 의미는 다음과 같습니다 당신은 매우 비슷한 일을 완전히 플러시 아웃 규칙을보고 싶다면, 내가 open source exemple

service cloud.firestore { 
    match /databases/{database}/documents { 
    match /usuarios/{uid} { 
     // Give write access to any field within the document who's id is the uid 
     // Add other validation as needed. 
     allow write: if uid == request.auth.uid 
      // Give admin access to anyone who's `level == 0` 
      // Make sure to add the `databases...` boilerplate 
      || get(/databases/$(database)/documents/usuarios/$(request.auth.uid)).data.level == 0; 

     // If necessary, give access to sub-collections. 
     // (We can't do it for uid or it will become a path object that we can't use as a string.) 
     /{sub=**} { 
     allow write: if uid == request.auth.uid; 
     } 
    } 
    } 
} 

. 건배!

+0

죄송하지만 "레벨"로 사용자가 필요합니다. 0은 다른 모든 사용자에게 쓸 수 있습니다. 관리자와 같습니다. 규칙에 따라 사용자는 자신의 "프로필"에 쓸 수 있습니다. 그렇습니까? –

+0

오, 알겠습니다. 업데이트 된 답변보기 (관리자 권한으로 OR 문 추가) – SUPERCILEX