Created
October 25, 2019 05:21
-
-
Save AniketSK/03d577ff12a8af5a2e9aeefb80544cf9 to your computer and use it in GitHub Desktop.
Some sample firebase rules.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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