I have a firebase project and I'm using FirebaseAuth and firebase database.
I only have one collection named baby, with name (String), userId (String), and votes (Integer) attributes. userId contians the user.uid of the creator.
I want to create a rule so that only the creator user can update or delete a document. Anyone can read and a registered user can create.
So I have the follwing rules:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /baby/{userId} {
allow read;
allow create: if request.auth.uid != null;
allow update, delete: if request.auth.uid == userId;
}
}
}
With this, anyone can read, a registered user can create. However, the user with uid=userId can't update. Any one knows where is the problem?
I've checked the database, and the userID attribute of the documents is correct (same as the user uid).
Thanks