Skip to content

Instantly share code, notes, and snippets.

@rockwotj
Last active January 20, 2016 16:32
Show Gist options
  • Save rockwotj/e65f8829d514940dba2e to your computer and use it in GitHub Desktop.
Save rockwotj/e65f8829d514940dba2e to your computer and use it in GitHub Desktop.
Firebase bolt rules for the Weatherpics With Auth App
type Weatherpic {
caption: String | Null,
imageUrl: String,
uid: UserID
}
type UserID extends String;
path /weatherpics {
read() { true }
index() { "uid" }
}
path /weatherpics/{pic} is Weatherpic {
write() { accessByCurrentUser(this.uid, prior(this.uid)) }
}
accessByCurrentUser(newUid, oldUid) { auth != null && ( created(newUid, oldUid) || edited(newUid, oldUid)|| deleted(newUid, oldUid) ) }
created(newUid, oldUid) { newUid == auth.uid && oldUid == null }
edited(newUid, oldUid) { newUid == auth.uid && newUid == oldUid }
deleted(newUid, oldUid) { oldUid == auth.uid && newUid == null }
{
"rules": {
"weatherpics": {
".read": "true",
".indexOn": [
"uid"
],
"$pic": {
".validate": "newData.hasChildren(['imageUrl', 'uid'])",
"caption": {
".validate": "newData.isString() || newData.val() == null"
},
"imageUrl": {
".validate": "newData.isString()"
},
"uid": {
".validate": "newData.isString()"
},
"$other": {
".validate": "false"
},
".write": "auth != null && (newData.child('uid').val() == auth.uid && data.child('uid').val() == null || newData.child('uid').val() == auth.uid && newData.child('uid').val() == data.child('uid').val() || data.child('uid').val() == auth.uid && newData.child('uid').val() == null)"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment