-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
64 lines (55 loc) · 2.45 KB
/
Copy pathfirestore.rules
File metadata and controls
64 lines (55 loc) · 2.45 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
55
56
57
58
59
60
61
62
63
64
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper function to check if the user is authenticated
function isAuth() {
return request.auth != null;
}
// -------------------------
// Users Collection
// -------------------------
match /users/{userId} {
// Anyone authenticated can read user profiles (needed for search and community)
allow read: if isAuth();
// Only the user can write to their own main document
allow write: if isAuth() && request.auth.uid == userId;
// User Data Subcollections (e.g., profile, schedule)
match /data/{docId} {
// Publicly readable so others can view profiles
allow read: if isAuth();
allow write: if isAuth() && request.auth.uid == userId;
}
// Workouts
match /workouts/{workoutId} {
// Anyone can read (frontend filters visibility/friendship)
allow read: if isAuth();
allow write: if isAuth() && request.auth.uid == userId;
}
// Sessions (Workout History)
match /sessions/{sessionId} {
// Only the user can read and write their own history
allow read, write: if isAuth() && request.auth.uid == userId;
}
// Friends Subcollection
match /friends/{friendId} {
// Anyone authenticated can check friends list
allow read: if isAuth();
// Only the user (or backend operations) can write to their friends list
allow write: if isAuth() && request.auth.uid == userId;
}
}
// -------------------------
// Friend Requests Collection
// -------------------------
match /friendRequests/{requestId} {
allow get: if isAuth() && (resource == null || resource.data.from == request.auth.uid || resource.data.to == request.auth.uid);
allow list: if isAuth() && (resource.data.from == request.auth.uid || resource.data.to == request.auth.uid);
// Users can create a request if they are the sender
allow create: if isAuth() && request.resource.data.from == request.auth.uid;
// Users can update if they are the receiver (e.g. to accept/reject)
allow update: if isAuth() && resource.data.to == request.auth.uid;
// Users can delete if they are either sender or receiver
allow delete: if isAuth() && (resource.data.from == request.auth.uid || resource.data.to == request.auth.uid);
}
}
}