-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
57 lines (45 loc) · 1.84 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
55
56
57
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isMyConversation() {
return isLoggedUser() && (request.auth.uid == resource.data.user_1_id || request.auth.uid == resource.data.user_2_id ) ;
}
function isInsideMyConversation(conversationId) {
return (get(/databases/$(database)/documents/conversations/$(conversationId)).data.user_1_id == (request.auth.uid) )||
(get(/databases/$(database)/documents/conversations/$(conversationId)).data.user_2_id == (request.auth.uid))
}
function isLoggedUser() {
return request.auth != null;
}
function myResource(myId) {
return isLoggedUser() && (request.auth.uid ==myId)
}
match /{document=**} {
allow read, write: if false;
}
match /conversations/{conversationId} {
allow read, write: if isMyConversation();
allow create, update: if isLoggedUser();
}
match /conversations/{conversationId}/messages/{messageId} {
allow read, write: if isInsideMyConversation(conversationId);
}
match /users/{userId} {
allow read, write, create: if isLoggedUser();
}
match /users/{userId}/friends/{friendId} {
allow create, update: if (friendId == request.auth.uid) || myResource(userId)
}
match /users/{userId}/friends/{friendId} {
allow read: if myResource(userId);
}
match /emails/{emailId} {
allow create: if isLoggedUser() && request.resource.data.to != request.auth.token.email
}
match /friendRequests/{requestId} {
allow read: if true;
allow create: if isLoggedUser() && request.resource.data.from == request.auth.token.email
allow delete : if isLoggedUser() && get(/databases/$(database)/documents/friendRequests/$(requestId)).data.to == request.auth.token.email
}
}
}