Skip to content

Instantly share code, notes, and snippets.

@yota345
Last active February 10, 2020 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yota345/ac91c68f54fb4bd0aa533fc5c7905e66 to your computer and use it in GitHub Desktop.
Save yota345/ac91c68f54fb4bd0aa533fc5c7905e66 to your computer and use it in GitHub Desktop.
Firestore security rule
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