-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
40 lines (33 loc) · 1.26 KB
/
Copy pathfirestore.rules
File metadata and controls
40 lines (33 loc) · 1.26 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
function isValidString(stringToValidate) {
return stringToValidate is string && stringToValidate.trim() != "";
}
function isValidDog() {
return isValidString(request.resource.data.name) &&
isValidString(request.resource.data.breed) &&
isValidString(request.resource.data.size) &&
isValidString(request.resource.data.description)
}
function isMessageAllowed(chatId) {
return request.auth.uid in get(/databases/$(database)/documents/chats/$(chatId)).data.userIds;
}
match /dogs/{dogId} {
allow read: if request.auth != null;
allow create, update: if request.auth.uid == request.resource.data.userId && isValidDog();
allow delete: if false;
}
match /chats/{chatId} {
allow read: if request.auth.uid in resource.data.userIds;
allow write: if false;
match /messages/{messageId} {
allow read: if isMessageAllowed(chatId);
allow create: if isMessageAllowed(chatId) && request.auth.uid == request.resource.data.userId;
allow update, delete: if false;
}
}
}
}
}