firebasefirebase-realtime-databasefirebase-authentication

Keep getting permission denied with newData.hasChildren


My current Firebase setup looks like:

{
  "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   
        }
      }
    }
  }
}

Then in the simulator I have:

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"
}

Then when I click RUN, I get this error:

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

Solution

  • So, it turns out that I needed to supply an expense_id. In the simulator I needed

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