mirror of
https://github.com/Dannecron/ich-lerne-deutsch.git
synced 2025-12-25 12:52:35 +03:00
Add firestore security rules example
This commit is contained in:
29
data/firestore-rules.txt
Normal file
29
data/firestore-rules.txt
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user