-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
47 lines (41 loc) · 1.87 KB
/
Copy pathfirestore.rules
File metadata and controls
47 lines (41 loc) · 1.87 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Default deny
match /{document=**} {
allow read, write: if false;
}
function isValidId(id) {
return id is string && id.size() <= 128 && id.matches('^[a-zA-Z0-9_\\-]+$');
}
function isSignedIn() {
return request.auth != null;
}
function isOwner(userId) {
return isSignedIn() && request.auth.uid == userId;
}
// --- Users ---
match /users/{userId} {
allow get: if isOwner(userId);
allow create: if isOwner(userId) && request.resource.data.keys().hasAll(['uid', 'email'])
&& request.resource.data.uid == request.auth.uid;
allow update: if isOwner(userId) && request.resource.data.diff(resource.data).affectedKeys().hasOnly(['displayName', 'photoURL']);
}
// --- Workspaces ---
match /workspaces/{workspaceId} {
allow list: if isSignedIn() && resource.data.ownerId == request.auth.uid;
allow get: if isSignedIn() && resource.data.ownerId == request.auth.uid;
allow create: if isSignedIn() && request.resource.data.ownerId == request.auth.uid;
allow update: if isOwner(resource.data.ownerId) && request.resource.data.diff(resource.data).affectedKeys().hasOnly(['name', 'icon', 'gradient']);
allow delete: if isOwner(resource.data.ownerId);
// --- Tasks (Subcollection of Workspaces) ---
match /tasks/{taskId} {
allow list: if isSignedIn() && resource.data.ownerId == request.auth.uid;
allow get: if isSignedIn() && resource.data.ownerId == request.auth.uid;
allow create: if isSignedIn() && request.resource.data.ownerId == request.auth.uid;
allow update: if isSignedIn() && resource.data.ownerId == request.auth.uid;
allow delete: if isSignedIn() && resource.data.ownerId == request.auth.uid;
}
}
}
}