Reputation: 3227
I am developing chat plugin and there are two types users: Operators and visitors. However I can NOT succeed to add users.
Here is my security rules:
{
"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']))"
}
}
}
}
I got those log messages while adding user into Firebase DB in chat console:
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
How can I solve this issue?
I was wrong with $user_id
. It should be auth.user_id
in ".validate" part:
".validate": "(auth.user_id === newData.child('user_id').val() && newData.hasChildren(['name', 'type', 'status']))"
Upvotes: 1
Views: 715
Reputation: 13954
$user_id
is wrong. It should be auth.user_id
in the ".validate"
part:
".validate": "(auth.user_id === newData.child('user_id').val() && newData.hasChildren(['name', 'type', 'status']))"
Upvotes: 1