-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
54 lines (46 loc) · 1.5 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isAuthed() {
return (request.auth != null) && (request.auth.token.email_verified == true);
}
function isAdmin(accountId) {
return isAuthed() && get(/databases/$(database)/documents/accounts/$(accountId)/accountUsers/$(request.auth.uid)).data.role == "admin";
}
// auth tokens
match /authTokens/{documents=**} {
allow write: if false;
allow read: if false;
}
// accounts
match /accounts/{accountId} {
function accountExists() {
return exists(/databases/$(database)/documents/accounts/$(accountId));
}
allow read: if isAdmin(accountId) || !accountExists();
allow create: if isAdmin(accountId);
allow update: if isAdmin(accountId);
allow delete: if isAdmin(accountId);
match /accountUsers/{accountUser} {
allow read: if isAdmin(accountId);
allow create: if isAuthed() && !accountExists();
allow update: if isAdmin(accountId);
allow delete: if isAdmin(accountId);
}
match /{documents=**} {
allow read: if isAdmin(accountId);
allow write: if isAdmin(accountId);
}
}
// users
match /users/{userId} {
function isUser () {
return userId == request.auth.uid;
}
allow read: if isUser();
allow create: if isAuthed();
allow update: if isUser();
allow delete: if isUser();
}
}
}