-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
32 lines (26 loc) · 1.05 KB
/
firestore.rules
File metadata and controls
32 lines (26 loc) · 1.05 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
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 document
function isUser(userId) {
return isAuthenticated() && request.auth.uid == userId;
}
// Users collection rules
match /users/{userId} {
// Allow read if user is authenticated and accessing their own document
allow read: if isUser(userId);
// Allow create if the user is authenticated and creating their own document
allow create: if isUser(userId)
&& request.resource.data.uid == userId
&& request.resource.data.email == request.auth.token.email;
// Allow update if user is authenticated and updating their own document
allow update: if isUser(userId);
// Allow delete if user is authenticated and deleting their own document
allow delete: if isUser(userId);
}
}
}