I have recently been working with React and Firebase to create a project where I would need to find specific documents in my collection based on their fields.
Currently, the only way to do this is by the following:
let ref = myFirebase.firestore().collection("Users");
let refQuery = ref.where('Token', '==', userUID);
This will give me the result I am looking for but in my rules I would have to allow my user to allow list
or allow read
for the collection Users
. To my understanding, this will be a potential hazard because I'm allowing the user to go through all the users in my collection. Instead, I want to be able to keep my rules to only allow get
so only the user can retrieve his own information but it won't work with my query code above.
Is there anyway I can change my React query code to be able to put my rules to only allow get
for my user in my Users
collection?
Here is a snippet from my rules that I want to implement:
match /Users/{UsersDoc} {
allow create: if request.auth.uid != null;
allow update, delete, get: if request.auth.uid == resource.data.Token;
}