2017-01-18 7 views
0

を行った後firebaseにデータを追加 -は私のルールは次のようになります認証

{ 
"rules": { 
    "customer": { 
     "$user_id": { 
      ".write": false, 
      ".read" : "$user_id === auth.uid" 
     } 
    }, 
    "franchises": 
    { 
     ".read": true, 
     ".write": "root.child('customer').hasChild(newData.child('salon_id').val())" 
    } 
} 
} 

を私はsalon_idを持って、私はこのsalon_idが顧客に存在を確認するされフランチャイズ内のデータを追加したいですをuidとして使用します。

私はPERMISSION_DENIEDエラー

を取得しています:許可が

コードで編集

を否定 -

var ref = firebase.database().ref('franchises'); 
ref.push({ 
    address: address, 
    contact_no: contact_no, 
    contact_person_name: contact_person_name, 
    name: textinputPlaceName, 
    salon_id: salon_id 
}); 

データは次のようになります - enter image description here

+0

このエラーメッセージの原因となる最小限のコードは表示されません。 –

+0

データ構造を投稿する必要はありますか? – Anirban

+0

含まれているエラーメッセージは、特定のコードを実行するとトリガーになります。質問に問題を引き起こす最小限のコードを含める必要があります。 –

答えて

0

あなたのルールでのレベルが不足している:あなたはfranchisesに書き込むとき

"franchises": { 
    ".read": true, 
    ".write": "root.child('customer').hasChild(newData.child('salon_id').val())" 
} 

これが適用されます。しかし、あなたのコードがref.push()を呼び出すので、あなたは1レベル深く書く。したがって、ルールは次のようにする必要があります。

"franchises": { 
    ".read": true, 
    "$franchiseId": { 
     ".write": "root.child('customer').hasChild(newData.child('salon_id').val())" 
    } 
} 
+0

同じことがまだPERMISSION_DENIEDになっています – Anirban

+0

私はコードを更新するために必要なルールを更新しましたか? – Anirban

+0

$ franchiseIdをpush()として渡しているので、問題を引き起こしている可能性があります。それは@フランクですか? – Anirban

関連する問題