I am really struggling with firebase database security rules.
I am working on a simple app, where users can maintain a list of records, which anyone can read but only the user who created the record can edit or delete.
Just consider it like a todo app, where authenticated users can manage list of tasks. Users can read each others task list but only the user who created the task can delete or edit it.
I have tried different options but failed to come up with correct security policy.
Is there any example I can follow or any recommendation on how to structure the data to simplify security policy ?
Sample security rule
I have tried something like this -
"rules": {
"records" : {
".read" : true,
"$user_id": {
".write": "auth.uid === $user_id"
}
}
}
}
So that anyone can read records but only logged in user with matching user_id should be able to add, edit or delete a record.
However, when I try a write action in simulator, I always get write denied error. I am passing the auth uid as "user_id" in request body/data.
I have also tried
{
"rules": {
"records" : {
".read" : true,
".write": "auth.uid === data.child('user_id').val()"
}
}
}