-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
61 lines (46 loc) · 1.96 KB
/
firestore.rules
File metadata and controls
61 lines (46 loc) · 1.96 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// helper functions
function isEmailVerified(request) {
return request.auth.token.email_verified;
}
function adminExists(businessID, adminID) {
return exists(/databases/$(database)/documents/businesses/$(businessID)/admins/$(adminID));
}
function employeeExists(businessID, employeeID) {
return exists(/databases/$(database)/documents/businesses/$(businessID)/employees/$(employeeID));
}
function getAdminBusinessID(businessID, adminID) {
return get(/databases/$(database)/documents/businesses/$(businessID)/admins/$(adminID)).data.businessID;
}
function getUserBusinessID(userID) {
return get(/databases/$(database)/documents/users/$(userID)).data.businessID;
}
// match admin documents during collectionGroup queries
match /{path=**}/admins/{adminID} {
// let admins read their own documents
allow read: if request.auth.uid == resource.data.adminID;
// don't let anyone update their admin document except through the backend
allow write: if false;
}
// match employee documents during collectionGroup queries
match /{path=**}/employees/{employeeID} {
// let employees read their own documents
allow read: if request.auth.uid == resource.data.employeeID;
// don't let anyone update their admin document except through the backend
allow write: if false;
}
// match business documents and their subcollections
match /businesses/{businessID}/{document=**} {
// let verified admins read the business doc they belong to
allow read: if adminExists(businessID,request.auth.uid) || employeeExists(businessID,request.auth.uid);
// don't let anyone write to business documents
allow write: if false;
}
// don't let anyone read or write mail documents
match /mail/{mailID} {
allow read, write: if false;
}
}
}