Firebase:使用newData.hasChildren继续获取权限

时间:2018-04-22 04:32:56

标签: firebase firebase-realtime-database firebase-authentication

所以我当前的Firebase设置如下:

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null",
    "users": {
      "$user_id": {
        ".read": "$user_id === auth.uid",
        ".write": "$user_id === auth.uid",
        "expenses": {
       "$expense_id": {
            ".validate": "newData.hasChildren(['description', 'note', 'createdAt', 'amount', 'status'])",
          "description": {
            ".validate": "newData.isString() && newData.val().length > 0"
          }, 
          "note": {
            ".validate": "newData.isString()"
          }, 
          "createdAt": {
            ".validate": "newData.isNumber()"
          }, 
          "amount": {
            ".validate": "newData.isNumber()"
          }, 
          "status": {
            ".validate": "newData.isNumber()"
          }, 
          "$other": {
            ".validate": false
          }
        }
    },
    "$other": {
        ".validate": false   
        }
      }
    }
  }
}

然后在模拟器中我有:

Write (check)
/users/84bdc53b-ad09-425a-a6fe-7c1a658cf7b4/expenses

Data JSON

{ 
"description": "asdf",
"note": "",
"amount": 0,
"createdAt": 0,
"status":0
}

Authenticated (check)
Provider: Custom
Not Admin
Auth Token Payload:
{
  "provider": "anonymous",
  "uid": "84bdc53b-ad09-425a-a6fe-7c1a658cf7b4"
}

然后,当我点击RUN时,我收到此错误:

Line 11 (/users/84bdc53b-ad09-425a-a6fe-7c1a658cf7b4/expenses/amount)
validate: "newData.hasChildren(['description', 'note', 'createdAt', 'amount', 
'status'])"

任何帮助将不胜感激! 这只是一些填充文字,所以我可以发布这个问题。不需要更多的写作,因为所有的基础知识都在代码中......但如果这里有更多的需要,那就是。

1 个答案:

答案 0 :(得分:0)

所以,事实证明我需要提供expense_id。在我需要的模拟器中

/users/84bdc53b-ad09-425a-a6fe-7c1a658cf7b4/expenses/abc123 // <------expense id