-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathfirestore.rules
More file actions
40 lines (28 loc) · 1.04 KB
/
firestore.rules
File metadata and controls
40 lines (28 loc) · 1.04 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
service cloud.firestore {
match /databases/{database}/documents {
function userOwnsCourse(userId, courseId) {
return exists(/databases/$(database)/documents/users/$(userId)/coursesOwned/$(courseId))
}
function isSubscriber(userId) {
return "pricingPlanId" in get(/databases/$(database)/documents/users/$(userId)).data
}
function isUserWithId(userId) {
return request.auth.uid == userId;
}
match /courses/{courseId} {
allow read: if true;
match /lessons/{lessonId} {
allow read: if userOwnsCourse(request.auth.uid,courseId) || isSubscriber(request.auth.uid)
}
}
match /purchaseSessions/{purchaseId} {
allow read: if request.auth.uid == resource.data.userId;
}
match /users/{userId} {
allow read: if isUserWithId(userId);
match /coursesOwned/{courseId} {
allow read: if isUserWithId(userId);
}
}
}
}