Skip to content

Commit

Permalink
attempt to edit firestore
Browse files Browse the repository at this point in the history
  • Loading branch information
hero346 committed Apr 17, 2024
1 parent 6513ebb commit 620cbad
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
27 changes: 13 additions & 14 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
"hosting": {
"public": "build",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
"firestore": {
"rules": "firestore.rules"
}
}
28 changes: 28 additions & 0 deletions firestore.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {

// by default disallow
match /{document=**} {
allow read, write: if false;
}

//chat
match /messages/{docId} {
allow read: if request.auth.uid != null;
allow create: if canCreateMessage();
}

function canCreateMessage() {
let isSignedIn = request.auth.uid != null;
let isOwner = request.auth.uid == request.resource.data.uid;
let isNotLong = request.resource.data.text.size() < 255;
let isNow = request.time == request.resource.data.createdAt;

let isNotBanned = /databases/$(database)/documents/User/$(request.auth.uid)/banned == false;

return isSignedIn && isOwner && isNotLong && isNow && isNotBanned;
}

}
}

0 comments on commit 620cbad

Please sign in to comment.