2016-10-05 4 views
-1

Firebaseのルールをはじめて設定しようとしています。私がしたいのは、ログインしたユーザーが自分のデータにしかアクセスできないようにアクセスを制限することです。自分のデータはusersusercontactsです。誰でもルートに書き込むことができ、誰も読むことができません。Firebaseのデータを保護する

このルールは、私が期待していることをしていますか?私はシミュレータで試して、simulated write deniedエラーが発生しました。私はシミュレータで何か間違ったことをしている可能性があります。

{ 
    "rules": { 
    "users": { 
     "$user_id": { 
     // grants read/write access to the owner of this user account 
     // whose uid must exactly match the key ($user_id) 
     ".write": "$user_id === auth.uid", 
     ".read": "$user_id === auth.uid" 
     } 
    }, 
    "usercontacts":{ 
     "$user_id": { 
       ".write": "$user_id === auth.uid", 
       ".read": "$user_id === auth.uid" 
     } 
    }, 
    "contactmessages": { 
     ".read" : false, 
     ".write" : "$user_id === auth.uid" 
    } 
    } 
} 
+0

あなたはあなたの質問を編集できますあなたが試みている書き込み操作を含めるには失敗しますか?あなたが書いたフルパス、アクティブなuid(もしあれば)、あなたが書いているデータ、そして既存のデータ(それはwrite +ルールに関連しています)です。 –

答えて

0

を試してみてくださいここでの問題は、あなたの最後の書き込みのルールである:

"contactmessages": { 
    ".read" : false, 
    ".write" : "$user_id === auth.uid" 
} 

あなたは$ USER_IDを使用しているだけに参照する任意の$のUSER_IDはありません。あなたは誰もがここに書くことができるようにしたい場合は代わりに、あなたは、このルールを使用する必要があります。

".write" : true 

それとも、このルールあなたは、すべての認証されたユーザーが書き込みできるようにしたい場合:

".write" : "auth != null" 
0

この

{ 
    "rules": { 
    "users": { 
     "$userId":{ 
      ".read": "(auth != null) && ($userId === auth.uid)", 
      ".write": "(auth != null) && ($userId === auth.uid)" 
     } 
    }, 
    "usercontacts": { 
     "$userId": { 
       ".read": "(auth != null) && ($userId === auth.uid)", 
       ".write": "(auth != null) && ($userId === auth.uid)" 
     } 
     }, 
     "contactmessages": { 
     "$userId": { 
       ".read": "(auth != null) && ($userId === auth.uid)", 
       ".write": "(auth != null) && ($userId === auth.uid)" 
     } 
     } 
    } 
} 
関連する問題