11rules_version = ' 2' ;
2-
32service cloud .firestore {
43 match / databases/ {database }/ documents {
5- // Helper functions
6- function isAuthenticated () {
7- return request .auth != null ;
8- }
9-
10- function isOwner (userId ) {
11- return isAuthenticated () && request .auth.uid == userId;
4+ // Base rule - deny access by default
5+ match / {document =** } {
6+ allow read , write : if false ;
127 }
138
14- // Users collection
9+ // User data - allow users to access their own data
1510 match / users/ {userId } {
16- // Users can read and update their own profiles
17- allow read , update : if isOwner (userId );
18- // Only allow creation through Cloud Functions (triggered by Auth)
19- allow create : if false ;
20- // Only allow deletion through Cloud Functions
21- allow delete : if false ;
11+ allow read , write : if request .auth != null && request .auth.uid == userId;
2212
23- // Add rules for documents subcollection
24- match / documents/ {documentType } {
25- allow read : if isOwner (userId );
26- // Allow Cloud Functions to write to this collection
27- allow write : if false ;
13+ // Allow access to documents subcollection
14+ match / documents/ {documentId } {
15+ allow read , write : if request .auth != null && request .auth.uid == userId;
2816 }
2917
30- // Add rules for predictions subcollection
18+ // Allow access to data subcollection
19+ match / data/ {dataId } {
20+ allow read , write : if request .auth != null && request .auth.uid == userId;
21+ }
22+
23+ // Allow access to predictions subcollection
3124 match / predictions/ {predictionId } {
32- allow read : if isOwner (userId );
33- allow write : if false ;
25+ allow read , write : if request .auth != null && request .auth.uid == userId;
26+ }
27+
28+ // Allow access to calculations subcollection
29+ match / calculations/ {calculationId } {
30+ allow read , write : if request .auth != null && request .auth.uid == userId;
3431 }
35- }
36-
37- // Courses collection - will be implemented later
38- match / courses/ {courseId } {
39- // Users can read courses they're enrolled in
40- allow read : if isAuthenticated () &&
41- exists (/ databases/ $(database )/ documents/ users/ $(request .auth.uid )/ courses/ $(courseId ));
42- // Write operations will be handled by Cloud Functions
43- allow write : if false ;
44- }
45-
46- // Default deny all
47- match / {document =** } {
48- allow read , write : if false ;
4932 }
5033 }
51- }
34+ }
0 commit comments