Skip to content

Instantly share code, notes, and snippets.

@sararob
Created August 25, 2015 17:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sararob/c99560e94a1d6bc2d5db to your computer and use it in GitHub Desktop.
Save sararob/c99560e94a1d6bc2d5db to your computer and use it in GitHub Desktop.
Upvoting example for Firebase security rules
{
"rules": {
".read": true,
"articles": {
"$article": {
"title": {
".write": "auth != null",
".validate": "newData.isString() && newData.val() != ''"
},
"url": {
".write": "auth != null",
".validate": "newData.isString() && newData.val() != '' && newData.val().matches(/^http.*$/)"
},
"votes": {
".write": "root.child('users').child(auth.uid).child('votes').child($article).val() != true"
},
"user": {
".write": "auth != null"
}
}
},
"users": {
"$user": {
".write": "auth != null && auth.uid === $user",
"votes": {
"$vote": {
".write": "!data.exists()"
}
}
}
}
}
}
@nelix
Copy link

nelix commented Nov 7, 2015

Won't this mean a user can only vote once, but when they vote they can change votes t whatever they want?

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