Skip to content

[DOCS] Update Readme to include firestore.rules update which resolves permission error #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,31 @@ service cloud.firestore {
function signedIn() {
return request.auth != null;
}

function isAdmin() {
return signedIn() &&
return signedIn() &&
'ADMIN'in get(/databases/$(database)/documents/users/$(request.auth.uid)).data.roles.values();
}
function ownsMessage() {

function isOwner() {
return signedIn() && request.auth.uid == resource.data.userId;
}

function isSelf() {
return signedIn() && request.auth.uid == resource.id;
}

// Rules
match /users/{userId} {
allow get: if isSelf();
allow list: if isAdmin();
allow write: if isSelf() || isAdmin();
allow get, update, delete: if isSelf() || isAdmin();
allow create: if signedIn();
}

match /messages/{messageId} {
allow read: if signedIn();
allow create: if signedIn();
allow update, delete: if signedIn() && ownsMessage();
allow create: if signedIn() && request.resource.data.userId == request.auth.uid;
allow update, delete: if signedIn() && isOwner();
}
}
}
Expand Down