-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
120 lines (107 loc) · 4.49 KB
/
firestore.rules
File metadata and controls
120 lines (107 loc) · 4.49 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// User profiles: users can read/write their own profile
match /users/{userId} {
allow read: if true;
allow write: if request.auth != null && request.auth.uid == userId;
// Friends subcollection: only the user can manage their friends
match /friends/{friendId} {
allow read: if request.auth != null && request.auth.uid == userId;
allow write: if request.auth != null && request.auth.uid == userId;
}
}
// Game records: authenticated users can create their own records, read all
match /gameRecords/{recordId} {
allow read: if request.auth != null;
allow create: if request.auth != null
&& request.resource.data.userId == request.auth.uid
&& request.resource.data.score is number
&& request.resource.data.score >= 0;
allow update, delete: if false;
}
// Leaderboards: public read, write only via admin SDK (Cloud Functions)
match /leaderboards/{themeId}/entries/{userId} {
allow read: if true;
allow write: if false;
}
// Friend requests: sender can create, recipient can update status
match /friendRequests/{requestId} {
allow read: if request.auth != null
&& (resource.data.fromUserId == request.auth.uid
|| resource.data.toUserId == request.auth.uid);
allow create: if request.auth != null
&& request.resource.data.fromUserId == request.auth.uid
&& request.resource.data.status == 'pending';
allow update: if request.auth != null
&& resource.data.toUserId == request.auth.uid
&& request.resource.data.status in ['accepted', 'declined'];
allow delete: if false;
}
// Challenges: only participants can read/write
match /challenges/{challengeId} {
allow read: if request.auth != null
&& (resource.data.challengerId == request.auth.uid
|| resource.data.challengedId == request.auth.uid);
allow create: if request.auth != null
&& request.resource.data.challengerId == request.auth.uid
&& request.resource.data.status == 'pending';
allow update: if request.auth != null
&& (resource.data.challengerId == request.auth.uid
|| resource.data.challengedId == request.auth.uid);
allow delete: if false;
}
// Events: readable by all authenticated users
match /events/{eventId} {
allow read: if request.auth != null;
allow create, delete: if false;
allow update: if false;
// Event standings: users can read all, write their own
match /standings/{userId} {
allow read: if request.auth != null;
allow create: if request.auth != null
&& request.auth.uid == userId;
allow update: if request.auth != null
&& request.auth.uid == userId;
allow delete: if false;
}
// Event game records: authenticated users can create their own
match /gameRecords/{recordId} {
allow read: if request.auth != null;
allow create: if request.auth != null
&& request.resource.data.userId == request.auth.uid
&& request.resource.data.score is number
&& request.resource.data.score >= 0;
allow update, delete: if false;
}
}
// Matches: only participants can read/write
match /matches/{matchId} {
allow read: if request.auth != null
&& (resource.data.player1Id == request.auth.uid
|| resource.data.player2Id == request.auth.uid);
allow create: if request.auth != null
&& (request.resource.data.player1Id == request.auth.uid
|| request.resource.data.player2Id == request.auth.uid);
allow update: if request.auth != null
&& (resource.data.player1Id == request.auth.uid
|| resource.data.player2Id == request.auth.uid);
allow delete: if false;
// Per-player live state
match /state/{playerId} {
allow read: if request.auth != null;
allow write: if request.auth != null
&& request.auth.uid == playerId;
}
}
// Matchmaking: authenticated users can manage their own entries
match /matchmaking/{entryId} {
allow read: if request.auth != null;
allow create: if request.auth != null
&& request.resource.data.userId == request.auth.uid;
allow update: if request.auth != null;
allow delete: if request.auth != null
&& resource.data.userId == request.auth.uid;
}
}
}