how to pass firestore auth token using flutter cloud_firestore package

情到浓时终转凉″ 提交于 2020-01-04 01:53:11

问题


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:


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.



来源:https://stackoverflow.com/questions/52812514/how-to-pass-firestore-auth-token-using-flutter-cloud-firestore-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!