Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass firestore auth token using flutter cloud_firestore package

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);
like image 752
stt106 Avatar asked Oct 15 '18 08:10

stt106


1 Answers

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.

like image 200
stt106 Avatar answered Oct 23 '22 21:10

stt106