I am trying to let the authorized current user read and write to his own data to the Firebase database. My security data looks like this:
{
"features" : {
"-KDUBJIPwvLCK-1lV4bM" : {
"e1fd0ccb-370a-4a6f-86af-87fdf97d25a0" : "een"
},
"-KDUBLUr6K_PMxWkgcof" : {
"e1fd0ccb-370a-4a6f-86af-87fdf97d25a0" : "twee"
}
},
"users" : {
"e1fd0ccb-370a-4a6f-86af-87fdf97d25a0" : {
"email" : "[email protected]",
"image" : "iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAYAAAB5fY51AAAAAXNSR0IArs4c6QAA\r\nABxpRE9UAAAA",
"name" : "tjalling dijkstra",
"telephone number" : "06580055"
}
}
}
-KDUBJIPwvLCK-1lV4bM
is an autoId gotten from childByAutoId()
method
e1fd0ccb-370a-4a6f-86af-87fdf97d25a0
is a uid (unique user id).
een
is the value of a certain feature.
My security rules are:
{
"rules": {
"users": {
"$uid": {
".read": "auth != null && auth.uid == $uid",
".write": "auth != null && auth.uid == $uid"
}
},
"features": {
"$autoId" : {
"$uid": {
".read": "auth != null && auth.uid == $uid",
".write": "auth != null && auth.uid == $uid"
}
}
}
}
}
If I write Firebase rules like this, permission to setValue()
is denied on the features part.
2016-03-22 17:51:27.077 Herodus[884:228445] [Firebase] setValue: or removeValue: at /features/-KDUEEZ4z-FCAoUci-rW failed: permission_denied.
A new feature is added with this code snippet:
let featureContents = addFeatureTextField.text
if featureContents != "" {
let newFeature: String = featureContents!
let featureDict = [ uid: newFeature]
let ref = DataService.dataService.FEATURE_REF.childByAutoId()
ref.setValue(featureDict)
Somebody, any clue what I am doing wrong here?