-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
36 lines (36 loc) · 1.12 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
rules_version = '2';
service cloud.firestore {
function signedIn(userId) {
return request.auth != null && request.auth.uid == userId;
}
function isValidTreePlan() {
let plan = request.auth.token.plan;
let treeType = request.resource.data.get('planId', null);
return treeType == null || treeType == "basic" || plan == treeType
}
match /databases/{database}/documents {
match /plans/{userId} {
allow read: if signedIn(userId);
}
match /trees/{treeId} {
allow read, write: if true;
}
match /users/{userId} {
allow read, write: if signedIn(userId);
}
match /users/{userId}/trees/{treeId} {
allow read, update: if signedIn(userId);
allow create: if signedIn(userId) && isValidTreePlan();
}
match /users/{userId}/proTrees/{treeId} {
allow read, update: if signedIn(userId);
allow create: if signedIn(userId) && request.auth.token.plan == "pro";
}
match /subscriptions/{userId} {
allow read, write: if signedIn(userId) && request.auth.token.email_verified;
}
match /{document=**} {
allow read, write: if false
}
}
}