From b79f31e7de7a7379bdd53aed8a2add118592666d Mon Sep 17 00:00:00 2001 From: dannc Date: Sat, 23 Mar 2019 11:09:02 +0700 Subject: [PATCH] Add firestore security rules example --- data/firestore-rules.txt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 data/firestore-rules.txt diff --git a/data/firestore-rules.txt b/data/firestore-rules.txt new file mode 100644 index 0000000..1aaeaf1 --- /dev/null +++ b/data/firestore-rules.txt @@ -0,0 +1,29 @@ +service cloud.firestore { + match /databases/{database}/documents { + function isAuthenticated() { + return request.auth.uid != null; + } + + function isAdmin() { + return isAuthenticated() + && get(/databases/$(database)/documents/userData/$(request.auth.uid)).data.isAdmin == true; + } + + match /articles/{document=**} { + allow read: if true; + allow write: if isAdmin(); + } + + match /articleParts/{document=**} { + allow read: if isAuthenticated() + && get(/databases/$(database)/documents/userData/$(request.auth.uid)) + .data + .articles[resource.data.articleId] != null; + allow write: if isAdmin(); + } + + match /userData/{userId} { + allow read, write: if isAuthenticated() || isAdmin(); + } + } +} \ No newline at end of file