为什么我无法验证用户?

时间:2013-08-14 17:22:45

标签: firebase firebase-security

我正在开发聊天插件,用户有两种类型:运营商和访客。但是我无法成功添加用户。

这是我的安全规则:

{
  "rules": {
    // By default, make all data private unless specified otherwise.
    ".read": "auth != null",
    ".write": "auth != null",

    // Only operators or user itself can update their data
    "users": {
      "$user_id": {
        ".read": "auth != null && ($user_id === auth.user_id || auth.operator === true)",
        ".write": "auth != null && ($user_id === auth.user_id || auth.operator === true)",
        ".validate": "($user_id === newData.child('user_id').val() && newData.hasChildren(['name', 'type', 'status']))"
      }
    }    
  }
}

我在聊天控制台中将用户添加到Firebase数据库时收到了这些日志消息:

Authenticated successfully with payload: Object {user_id: 112, is_operator: true}
Auth expires at: Thu Aug 15 2013 20:12:22 GMT+0300 (GTB Daylight Time)
FIREBASE: Attempt to write {"type":"operator","name":"op","user_id":112} to /users/operators/112 with auth={"user_id":112,"is_operator":true}
FIREBASE:   /:.write: "auth != null"
FIREBASE:       => true
FIREBASE:   /users/operators:.validate: "($user_id === newData.child('user_id').val() && newData.hasChildren(['name', 'type', 'status']))"
FIREBASE:       => false
FIREBASE: Validation failed.
FIREBASE: Write was denied.
FIREBASE WARNING: set at /users/operators/112 failed: permission_denied
(!) ERROR: Error: PERMISSION_DENIED :: auth() function while creating user

我该如何解决这个问题?

$user_id我错了。它应该是{。{1}}在“.validate”部分:

auth.user_id

1 个答案:

答案 0 :(得分:1)

$user_id错了。它应该是auth.user_id部分中的".validate"

".validate": "(auth.user_id === newData.child('user_id').val() && newData.hasChildren(['name', 'type', 'status']))"