-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
62 lines (52 loc) · 1.82 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
62
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper function to check if user is authenticated
function isAuthenticated() {
return request.auth != null;
}
// Helper function to check if user is accessing their own data
function isUserData(userId) {
return isAuthenticated() && request.auth.uid == userId;
}
// Settings
match /users/{userId}/settings/{document=**} {
allow read, write: if isUserData(userId);
}
// Food entries
match /users/{userId}/foodEntries/{date}/{document=**} {
allow read, write: if isUserData(userId);
}
// Daily progress
match /users/{userId}/progress/{document=**} {
allow read, write: if isUserData(userId);
}
// Workout plans and sessions
match /users/{userId}/workoutPlans/{planId} {
allow read, write: if isUserData(userId);
// Allow access to nested sessions collection
match /sessions/{sessionId} {
allow read, write: if isUserData(userId);
}
}
// Completed workout sessions
match /users/{userId}/completedSessions/{sessionId} {
allow read, write: if isUserData(userId);
}
// Foods collection (shared database)
match /foods/{foodId} {
// Anyone can read food entries
allow read: if isAuthenticated();
// Only authenticated users can create entries
allow create: if isAuthenticated() &&
request.resource.data.createdBy == request.auth.uid;
// Only the creator can update or delete their entries
allow update, delete: if isAuthenticated() &&
resource.data.createdBy == request.auth.uid;
}
// Disallow access to all other collections by default
match /{document=**} {
allow read, write: if false;
}
}
}