-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfirestore.rules
34 lines (29 loc) · 1.09 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /games/{gameId} {
function isOwner(request, resource) {
return request.auth != null && request.auth.uid == resource.data.ownerId;
}
function isShortCodeSearch(resource) {
return resource.data.state == "waitingForPlayers" && resource.data.shortCode != null
}
allow list: if isOwner(request, resource) || isShortCodeSearch(resource);
allow write: if isOwner(request, resource);
allow get: if true;
match /players/{playerId} {
allow read: if true;
allow write: if get(/databases/$(database)/documents/games/$(gameId)).data.state == "waitingForPlayers";
}
match /questions/{questionId} {
allow read: if true;
// could check the game's ownerId in the future
allow write: if request.auth != null;
}
match /answers/{answerId} {
allow read: if true;
allow write: if get(/databases/$(database)/documents/games/$(gameId)).data.state == "showingQuestion";
}
}
}
}