-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
42 lines (35 loc) · 1.16 KB
/
Copy pathfirestore.rules
File metadata and controls
42 lines (35 loc) · 1.16 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Default deny rule for any unmapped paths
match /{document=**} {
allow read, write: if false;
}
// Helper functions for security validation
function isAuthenticated() {
return request.auth != null;
}
function isOwner(uid) {
return isAuthenticated() && request.auth.uid == uid;
}
// User document profile (/users/{uid})
match /users/{uid} {
allow read, write: if isOwner(uid);
// User notes subcollection (/users/{uid}/notes/{noteId})
match /notes/{noteId} {
allow read, write, delete: if isOwner(uid);
}
// Active user sessions subcollection (/users/{uid}/sessions/{deviceId})
match /sessions/{deviceId} {
allow read, write, delete: if isOwner(uid);
}
}
// Public notes collection (/public_notes/{noteId})
// Shared notes are readable by anyone with the link.
// Client-side modifications/deletions are blocked (managed via Cloudflare Worker Admin SDK).
match /public_notes/{noteId} {
allow read: if true;
allow write: if false;
}
}
}