Skip to content

Instantly share code, notes, and snippets.

@rohitsuratekar
Created July 21, 2016 05:01
Show Gist options
  • Save rohitsuratekar/e04ffa8426ccfcf7a7528935b355e92a to your computer and use it in GitHub Desktop.
Save rohitsuratekar/e04ffa8426ccfcf7a7528935b355e92a to your computer and use it in GitHub Desktop.
FIrebase Rules
{
"rules":{
// Normal users will have access to only "users"
"users":{
"$user_id":{
// grants access to the owner of this user account
// whose uid must exactly match the key ($user_id)
".write":"$user_id === auth.uid",
".read":"$user_id === auth.uid"
}
},
// Moderators will have "read" access to "mods". You can add individual moderator's UID in this node
"mods" :{
".write":false,
".read":"root.child('mods').child(auth.uid).exists()"
},
//Store user details with their email ID as node.
//For this create another node with email IDs stored in their respective UID
"usersWithEmail":{
"$email_id": {
".write": "root.child('authEmails').child(auth.uid).val().replace('.', '_').replace('@', '_') == $email_id && auth !== null",
".read": "auth !== null"
}
},
"authEmails":{
"$user_id":{
// grants access to the owner of this user account
// whose uid must exactly match the key ($user_id)
".write":"$user_id === auth.uid",
".read":"$user_id === auth.uid"
}
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment