Collection of Firebase Security Rules
example snippets for my future use
Hypothetical blog
app
What I want
- All posts can be
read
by anyone
- A post can be
created
by any authenticated user
- A post can only be
updated/deleted
by the authenticated user who created the post
Security Rules for above
allow read;
// anyone
allow create: request.auth != null;
// authenticated user
allow update, delete: request.auth != null && request.auth.uid == resource.data.owner;
// authenticated user who created the post (owner in this case)
Distinction between request and resource
request
is an incoming request (data) from path matched
resource
is the existing data in Firestore that will be evaluated against the set Security Rules
Put them into functions
Security Rules for blog
app