6

I am using firebase auth REST api to do authentication; this part works fine as I can log in/sign up users and I can get a uid and auth token back.

When trying to write to cloud firestore, if I set my Cloud Firestore database rule to (which is one of the most basic auth rules):

service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read, write: if request.auth.uid != null; } } } 

But how to pass in the uid to the a cloud firestore request using cloud_firestore package e.g. I want to write to a collection:

Firestore.instance.collection('myCollection').document() .setData(myData); 
1
  • Did you get this working or did you just end up using the REST api? Commented Aug 12, 2019 at 15:18

1 Answer 1

4

Just in case this helps someone else, I was told that I shouldn't mix firebase auth REST api with firestore non-REST api. If I want to use cloud_firestore package, I shall use firebase_auth package too so that firebase_auth will take case of the underlying authentication without requiring cloud_firestore to pass any auth token explicitly.

In the meantime, firestore does have a REST api too; so if someone really wants to use firebase auth REST api, then firestore REST api should also be used so that an auth token can be passed explicitly.

Sign up to request clarification or add additional context in comments.

1 Comment

I find it incredible that cloud_firestore doesn't allow passing a token to verify the user's authentication in each request, as can be done with the rest of Firestore's api. If someone reads this in time, don't make my mistake, and use the rest api instead of cloud_firestore from the beginning of your project.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.