Im trying to set up rules for a Firestore Database.
Im having some trouble setting up rules for nested objects.
The database structure looks like this:
Users ( collection of User objects )
-----userDocument ( the name of the document matches the auth-users uid )
-----------------users ( subcollection of users )
-------------------------userdocument ( the name of the document matches the auth-users uid )
note: the last userDocument does not contain any references.
He has his own document in the main Users collection.
I want every user to have read/write access to every user in the Users collection, who has a matching ID of the users in his subcollection of users. Furthermore, any user should be able to create a new user on the database, as long as they are authenticated with firebase Auth.
I have tried following solutions, it doesnt work:
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId}{
allow read, write: if exists(/databases/$(database)/documents/users/userId/users/$(request.auth.uid)) || userId == request.auth.uid;
}
}
}
What i need is:
- A way to get all document names from the logged in userĀ“s subcollection of users
- A way to grant access to ONLY these users
The user has 1 user in his subcollection, so the user should have access to read/write his own user, and qb2pa1TWXHZr0NZUREealgWrOYb2.