-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfirestore.rules
38 lines (36 loc) · 1.19 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
35
36
37
38
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function userIsSignedIn() {
return request.auth != null;
}
match /{document=**} {
allow read: if userIsSignedIn();
allow write: if false;
}
match /games/{game} {
function gameData() {
return get(/databases/$(database)/documents/games/$(game)).data
}
function gameHasNotYetStarted() {
return gameData().state == 'waitingForPlayers';
}
allow create: if userIsSignedIn();
allow update: if resource.data.creatorId == request.auth.uid;
match /players/{player} {
function playerData() {
return get(/databases/$(database)/documents/games/$(game)/players/$(player)).data
}
function userIsThePlayer() {
return playerData().userId == request.auth.uid;
}
allow create: if gameHasNotYetStarted() && userIsSignedIn();
allow update: if userIsThePlayer();
allow delete: if userIsThePlayer() || gameData().creatorId == request.auth.uid;
match /answers/{answer} {
allow write: if userIsThePlayer();
}
}
}
}
}