2017-12-24 26 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

関連する問題