Skip to content

Instantly share code, notes, and snippets.

@takuwan0405 takuwan0405/sample.rule

Last active Feb 10, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.