-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfirestore.rules
36 lines (29 loc) · 842 Bytes
/
firestore.rules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// public collection is publicly accessible
match /public/{publicId} {
allow read, write: if true;
}
// analytics - only allow users to read
// TODO: move to API to utilize cache
match /analytics/{analyticId} {
allow read: if true;
allow write: if false;
}
// securities for authenticated users
match /users/{userId} {
allow read, write: if isOwner(userId) || isAdmin();
match /pdfs/{pdfId} {
allow read, write: if isOwner(userId) || isAdmin();
}
}
// HELPER FUNCTIONS
function isOwner(userId) {
return request.auth != null && request.auth.uid == userId;
}
function isAdmin() {
return request.auth.token.admin == true;
}
}
}