-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
44 lines (36 loc) · 1.03 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isAdmin() {
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'administrator'
}
function isCurrentUser(user) {
return request.auth.uid == user;
}
function noUpdateToAmin() {
return request.resource.data.role != 'administrator';
}
function canAccessChats() {
let isOwner = request.auth.uid in resource.data.members;
return isSignedIn() && isOwner;
}
function isSignedIn() {
return request.auth != null;
}
match /users/{docId} {
allow read: if isSignedIn();
allow write, update:
if isAdmin() || isCurrentUser(docId);
allow delete:
if isAdmin();
}
match /chats {
allow write: if isSignedIn();
allow read, update, delete: if canAccessChats();
}
match /chats/{docId} {
allow write: if isSignedIn();
allow read, update, delete: if canAccessChats();
}
}
}