Skip to content

Instantly share code, notes, and snippets.

@AniketSK
Created October 25, 2019 05:21
Show Gist options
  • Save AniketSK/03d577ff12a8af5a2e9aeefb80544cf9 to your computer and use it in GitHub Desktop.
Save AniketSK/03d577ff12a8af5a2e9aeefb80544cf9 to your computer and use it in GitHub Desktop.
Some sample firebase rules.
rules_version = '2';
function isAuthenticated(request){
return request.auth != null && request.auth.uid != null
}
function isDocUidSameAsUserUid(request){
return request.auth.uid == request.resource.data.uid
}
function userOwnsDocument(request, document){
return request.auth.uid == document.data.uid
}
service cloud.firestore {
match /databases/{database}/documents {
match /goals/{document} {
allow list;
allow create, delete: if isAuthenticated(request) && isDocUidSameAsUserUid(request);
allow read, write: if isAuthenticated(request) && userOwnsDocument(request, document) && isDocUidSameAsUserUid(request);
}
match /users/{userId}/privategoals/{document} {
allow create: if isAuthenticated(request) && isDocUidSameAsUserUid(request)
allow read, write: if isAuthenticated(request) && isDocUidSameAsUserUid(request) && userOwnsDocument(request, document)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment