This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfirestore.rules
61 lines (57 loc) · 1.7 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
service cloud.firestore {
match /databases/{database}/documents {
function ensureAuth() {
return request.auth != null;
}
function ensureUser(uid) {
return ensureAuth() && uid == request.auth.uid;
}
function isInvolved(data) {
return request.auth.uid in data.players;
}
match /decks/{deckId} {
allow create: if false;
allow update, delete: if resource.data.creator == request.auth.uid;
allow read: if ensureAuth();
}
match /games/{gameId} {
function isFinished() {
return resource.data.isFinished == true;
}
function isInvolvedInGame() {
return isInvolved(resource.data);
}
allow read: if ensureAuth() && isInvolvedInGame();
allow write: if false;
match /personal/{uid} {
allow read: if ensureAuth() && ensureUser(uid);
allow write: if false;
}
match /hidden/{uid} {
allow read, write: if false;
}
match /actions/{actionId} {
allow read: if ensureAuth() && isInvolvedInGame() && isFinished();
allow write: if false;
}
}
match /user-search/{uid} {
allow write: if false;
allow read: if ensureAuth();
}
match /lobby/{lobbyId} {
allow create: if ensureAuth();
allow update: if false;
allow delete: if ensureAuth() && isInvolved(resource.data);
allow read: if ensureAuth();
}
match /users/{uid} {
function validUsername(username) {
return username.matches('^[a-zA-Z0-9][a-zA-Z0-9_]*([.][a-z0-9_]+)*$') == true;
}
allow read: if ensureUser(uid);
allow write: if ensureUser(uid)
&& validUsername(request.resource.data.username);
}
}
}