-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
68 lines (56 loc) · 1.85 KB
/
firestore.rules
File metadata and controls
68 lines (56 loc) · 1.85 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
65
66
67
68
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// 1. Global Safety Net
match /{document=**} {
allow read, write: if false;
}
// Common primitives
function isSignedIn() {
return request.auth != null;
}
function isOwner(userId) {
return isSignedIn() && request.auth.uid == userId;
}
function isValidId(id) {
return id is string && id.size() <= 128 && id.matches('^[a-zA-Z0-9_\\-]+$');
}
// 2. User Profiles match
match /users/{userId} {
allow read: if isOwner(userId);
allow create: if isOwner(userId)
&& request.resource.data.uid == userId
&& request.resource.data.email is string
&& request.resource.data.theme in ['light', 'dark']
&& request.resource.data.monthlyIncome is number;
allow update: if isOwner(userId)
&& request.resource.data.uid == userId
&& request.resource.data.email == resource.data.email
&& request.resource.data.theme in ['light', 'dark']
&& request.resource.data.monthlyIncome is number;
allow delete: if isOwner(userId);
// Subcollections under users/{userId} are strictly owned by that user
match /transactions/{transactionId} {
allow read, write: if isOwner(userId);
}
match /budgets/{budgetId} {
allow read, write: if isOwner(userId);
}
match /savingsGoals/{goalId} {
allow read, write: if isOwner(userId);
}
match /notes/{noteId} {
allow read, write: if isOwner(userId);
}
match /tasks/{taskId} {
allow read, write: if isOwner(userId);
}
match /events/{eventId} {
allow read, write: if isOwner(userId);
}
match /notifications/{notificationId} {
allow read, write: if isOwner(userId);
}
}
}
}