Last active
February 10, 2020 17:07
-
-
Save yota345/ac91c68f54fb4bd0aa533fc5c7905e66 to your computer and use it in GitHub Desktop.
Firestore security rule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service cloud.firestore { | |
match /databases/{database}/documents { | |
function isOwn() { | |
return request.resource.userId == request.auth.uid; | |
} | |
function hasTimestamp() { | |
return request.resource.data.timestamp == request.time; | |
} | |
function isCalm() { | |
return request.time > resource.data.timestamp + duration.value(5, 's'); | |
} | |
function isBlackListed() { | |
return exists(/databases/$(database)/documents/blacklist/$(request.auth.uid)) | |
} | |
match /histories/{history} { | |
allow create: if isOwn() && hasTimestamp() && !isBlackListed(); | |
allow update: if isOwn() && hasTimestamp() && isCalm() && !isBlackListed(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment