Skip to content

Instantly share code, notes, and snippets.

@CurtisHumphrey
Last active October 1, 2018 20:44
Show Gist options
  • Save CurtisHumphrey/c5e81b2bd198d675263a to your computer and use it in GitHub Desktop.
Save CurtisHumphrey/c5e81b2bd198d675263a to your computer and use it in GitHub Desktop.
Firebase Rules Examples
// Supports pushing new items
"private": {
".read": false,
".write": false,
"$item": {
".read": "auth != null && auth.uid == data.child('uid').val()",
".write": "auth != null &&
/*update*/ ((data.exists() && auth.uid == data.child('uid').val())
/*new*/ || (!data.exists() && auth.uid == newData.child('uid').val()))"
}
}
//http://stackoverflow.com/questions/15079163/how-can-i-use-firebase-to-securely-share-presence-data-within-a-specific-group/15079164#15079164
// Protecting a group by checking if a user is part of the group
{
"groups": {
"$groupid": {
// Users can view the presence state of users in this group if they
// are authenticated and listed in the group themselves.
".read": "auth != null && data.child('users').hasChild(auth.id)",
// Only admins can create new groups.
".write": "auth != null && auth.isAdmin === true",
"users": {
"$userid": {
// Users can update only their individual account data.
".write": "auth != null && $userid == auth.id && newData.val() != null"
}
}
}
}
}
@Pawel-Janik
Copy link

Pawel-Janik commented Oct 1, 2018

Thx for sharing. Firebase docs really lack those examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment