I have a database at firebase and I would like to retrieve a particular document which I know its name (will be called documentA) and also I have a working rule at server.
How can I get a single document which fullfil the security rules? I am trying with: val docRef = db.collection("cities").document("SF").get()
but I don't know how to include user auth.
Database has a structure like this
cars
|
|-documentA
|-documentB
|-documentC
Security rules:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /cars/{carId} {
allow read, write: if request.auth.uid == resource.data.userId;
allow create: if request.auth.uid != null;
}
}
}
Firebase user authentication is included automatically for users who are signed in. Other than writing the code to signing in the user, there is no code you can write to add authentication manually. If your security rules require an authenticated user, you will have to arrange for that sign-in before the query is made.