Repository navigation
Expand file tree
/
Copy pathfirestore.rules
More file actions
93 lines (77 loc) · 3.52 KB
/
Copy pathfirestore.rules
File metadata and controls
93 lines (77 loc) · 3.52 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper functions
function isAuthenticated() {
return request.auth != null;
}
function isUser(userId) {
return isAuthenticated() && request.auth.uid == userId;
}
// -------------------------------------------------------------
// USERS COLLECTION
// -------------------------------------------------------------
match /users/{userId} {
// Any authenticated user can view profiles (for search, chat list, and status)
allow read: if isAuthenticated();
// Users can only create, edit, or delete their own profile document
allow create, update, delete: if isUser(userId);
}
// -------------------------------------------------------------
// FRIEND REQUESTS COLLECTION
// -------------------------------------------------------------
match /friend_requests/{requestId} {
// Read: sender or recipient
allow read: if isAuthenticated() &&
(resource.data.fromUid == request.auth.uid || resource.data.toUid == request.auth.uid);
// Create: sender must match authenticated user
allow create: if isAuthenticated() && request.resource.data.fromUid == request.auth.uid;
// Update & Delete: either sender or recipient
allow update, delete: if isAuthenticated() &&
(resource.data.toUid == request.auth.uid || resource.data.fromUid == request.auth.uid);
}
// -------------------------------------------------------------
// STATUSES & STATUS COLLECTIONS
// -------------------------------------------------------------
match /status/{statusId} {
allow read: if isAuthenticated();
allow create: if isAuthenticated() && request.resource.data.userId == request.auth.uid;
allow update: if isAuthenticated();
allow delete: if isAuthenticated() && resource.data.userId == request.auth.uid;
match /comments/{commentId} {
allow read: if isAuthenticated();
allow create, update, delete: if isAuthenticated();
}
match /views/{viewId} {
allow read: if isAuthenticated();
allow create, update, delete: if isAuthenticated();
}
}
match /statuses/{statusId} {
allow read: if isAuthenticated();
allow create: if isAuthenticated() && request.resource.data.userId == request.auth.uid;
allow update: if isAuthenticated();
allow delete: if isAuthenticated() && resource.data.userId == request.auth.uid;
}
// -------------------------------------------------------------
// CHATS & MESSAGES COLLECTIONS
// -------------------------------------------------------------
match /chats/{chatId} {
allow read, write: if isAuthenticated();
match /messages/{messageId} {
allow read: if isAuthenticated();
allow create: if isAuthenticated() && request.resource.data.senderId == request.auth.uid;
allow update, delete: if isAuthenticated();
}
}
// -------------------------------------------------------------
// REPORTS COLLECTION (App Issue & Bug Reports)
// -------------------------------------------------------------
match /reports/{reportId} {
// Logged-in users can submit reports under their own UID
allow create: if isAuthenticated() && request.resource.data.userId == request.auth.uid;
// Reports are confidential (users cannot read, update, or delete submitted reports)
allow read, update, delete: if false;
}
}
}