dragonfly02
dragonfly02

Reputation: 3679

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);

Upvotes: 6

Views: 2361

Answers (1)

dragonfly02
dragonfly02

Reputation: 3679

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.

Upvotes: 4

Related Questions