-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
100 lines (89 loc) · 3.74 KB
/
firestore.rules
File metadata and controls
100 lines (89 loc) · 3.74 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
94
95
96
97
98
99
100
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function signedIn() {
return request.auth != null;
}
function isSelf(uid) {
return signedIn() && request.auth.uid == uid;
}
// Public profile (read by any signed-in user for friends / discovery)
match /profiles/{userId} {
allow read: if signedIn();
allow create: if isSelf(userId);
allow update: if isSelf(userId);
allow delete: if false;
match /activity/{activityId} {
allow read: if signedIn();
allow create: if isSelf(userId);
allow update, delete: if isSelf(userId);
}
}
// username -> uid + signInEmail (for email/password login before auth).
// signInEmail is written only by the account owner when claiming username or on profile sync.
match /usernames/{handle} {
allow read: if true;
allow create: if signedIn()
&& request.resource.data.uid == request.auth.uid;
allow update, delete: if signedIn()
&& resource.data.uid == request.auth.uid;
}
// Directed invite: fromUid requests toUid; only recipient can accept
match /friendInvites/{inviteId} {
allow read: if signedIn()
&& (resource.data.fromUid == request.auth.uid
|| resource.data.toUid == request.auth.uid);
allow create: if signedIn()
&& request.resource.data.fromUid == request.auth.uid
&& request.resource.data.status == 'pending'
&& request.resource.data.fromUid != request.resource.data.toUid;
allow update: if signedIn()
&& resource.data.toUid == request.auth.uid
&& resource.data.status == 'pending'
&& request.resource.data.status == 'accepted'
&& request.resource.data.fromUid == resource.data.fromUid
&& request.resource.data.toUid == resource.data.toUid;
allow delete: if signedIn()
&& (resource.data.fromUid == request.auth.uid
|| resource.data.toUid == request.auth.uid);
}
match /tasks/{taskId} {
allow read: if signedIn() && resource.data.userId == request.auth.uid;
allow create: if signedIn()
&& request.resource.data.userId == request.auth.uid
&& request.resource.data.title is string;
allow update, delete: if signedIn()
&& resource.data.userId == request.auth.uid
&& request.resource.data.userId == resource.data.userId;
}
// Calendar events (e.g. scan-to-calendar); image URLs may point at Firebase Storage
match /events/{eventId} {
allow read: if signedIn() && resource.data.userId == request.auth.uid;
allow create: if signedIn()
&& request.resource.data.userId == request.auth.uid
&& request.resource.data.title is string
&& request.resource.data.date is string;
allow update, delete: if signedIn()
&& resource.data.userId == request.auth.uid
&& request.resource.data.userId == resource.data.userId;
}
match /sessions/{sessionId} {
allow read: if signedIn() && resource.data.userId == request.auth.uid;
allow create: if signedIn()
&& request.resource.data.userId == request.auth.uid;
allow update, delete: if signedIn()
&& resource.data.userId == request.auth.uid
&& request.resource.data.userId == resource.data.userId;
}
match /studyRooms/{roomId} {
allow read: if signedIn()
&& request.auth.uid in resource.data.members;
allow create: if signedIn()
&& request.resource.data.hostId == request.auth.uid
&& request.auth.uid in request.resource.data.members;
allow update: if signedIn()
&& request.auth.uid in resource.data.members;
allow delete: if signedIn() && resource.data.hostId == request.auth.uid;
}
}
}