1

ユーザーがトークン (招待状) を持っている場合にのみアカウントを作成できるようにしたい。私のfirebase Securityには次のものがあります:

{
"rules": {
  ".read": false,
  ".write": false,
  "users": {
    // allow to write if in the invitations there is child equal to token from newData()
    ".write":"root.child('invitations').hasChild(newData.child('token').val())",  
  },
 "invitations":{
   "$invitation":{
     ".read": "true"
   }
  }
}

}

コメントにあるように、招待状に newData() からのトークンに等しい子がある場合、書き込みを許可したいです。

シミュレーターから:

Attempt to write {"token":"evl6yky3vi0pmn29","name":"John"} to /users/99 with auth=null
/:.write: "false"
    => false
/users:.write: "root.child('invitations').hasChild(newData.child('token').val())"
6:52: hasChild() expects a string argument.
    => false
/users/99:<no rules>

どうすればいいですか?

4

1 に答える 1

4

ほぼ完璧です。ここでの唯一の欠点は、users/99 に書き込もうとしているのに、users/ にルールを設定していることです。

おそらく、あなたはこれを意味しました:

"users": {
   "$user_id": {
      // allow to write if in the invitations there is child equal to token from newData()
      ".write":"root.child('invitations').hasChild(newData.child('token').val())",  
   }
},
于 2013-12-09T15:08:23.327 に答える