-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
54 lines (48 loc) · 2.48 KB
/
firestore.rules
File metadata and controls
54 lines (48 loc) · 2.48 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper function to check if user is admin
function isAdmin() {
return request.auth != null &&
(request.auth.token.admin == true ||
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.isAdmin == true);
}
// User profile rules
match /users/{userId} {
allow read: if request.auth != null && request.auth.uid == userId;
allow write: if request.auth != null && request.auth.uid == userId;
}
// Exercise sessions rules
match /exerciseSessions/{sessionId} {
allow read: if request.auth != null && resource.data.userId == request.auth.uid;
allow create: if request.auth != null && request.resource.data.userId == request.auth.uid;
allow update: if request.auth != null && resource.data.userId == request.auth.uid;
allow delete: if request.auth != null && resource.data.userId == request.auth.uid;
}
// Badge definitions - readable by all authenticated users, writable by admins
match /badges/{badgeId} {
allow read: if request.auth != null;
// Allow any authenticated user to write badges for now (temporary fix)
allow write: if request.auth != null;
}
// User badges progress - each user can only read/write their own progress
match /userBadges/{userId} {
allow read: if request.auth != null && request.auth.uid == userId;
allow write: if request.auth != null && request.auth.uid == userId;
}
// Badge history - each user can only read/write their own history
match /badgeHistory/{historyId} {
allow read: if request.auth != null && resource.data.userId == request.auth.uid;
allow create: if request.auth != null && request.resource.data.userId == request.auth.uid;
allow update: if request.auth != null && resource.data.userId == request.auth.uid;
allow delete: if request.auth != null && resource.data.userId == request.auth.uid;
}
// Exercise feedback - each user can only read/write their own feedback
match /exerciseFeedback/{feedbackId} {
allow read: if request.auth != null && resource.data.userId == request.auth.uid;
allow create: if request.auth != null && request.resource.data.userId == request.auth.uid;
allow update: if request.auth != null && resource.data.userId == request.auth.uid;
allow delete: if request.auth != null && resource.data.userId == request.auth.uid;
}
}
}