Skip to content

Commit

Permalink
🔧 Add firebase configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
leodr committed Jan 31, 2021
1 parent 08478e0 commit 3a4b38c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "quice"
}
}
6 changes: 6 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"firestore": {
"indexes": "firebase/firestore.indexes.json",
"rules": "firebase/firestore.rules"
}
}
19 changes: 19 additions & 0 deletions firebase/firestore.indexes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"fieldOverrides": [],
"indexes": [
{
"collectionGroup": "submissions",
"fields": [
{
"fieldPath": "formId",
"order": "ASCENDING"
},
{
"fieldPath": "createdAt",
"order": "DESCENDING"
}
],
"queryScope": "COLLECTION"
}
]
}
31 changes: 31 additions & 0 deletions firebase/firestore.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}

function isUserOwner(form) {
return form.data.owner.type == 'user'
&& form.data.owner.id == request.auth.uid;
}

match /forms/{formId} {
allow read: if isUserOwner(resource);

allow write: if false;
}

function hasAccessToSubmission(formId) {
let form = get(/databases/$(database)/documents/forms/$(formId));

return isUserOwner(form);
}

match /submissions/{submissionId} {
allow read: if hasAccessToSubmission(resource.data.formId);

allow write: if false;
}
}
}

0 comments on commit 3a4b38c

Please sign in to comment.