I have a working flutter app which uses the cloud_firestore package, it's going well with Android and iOS. But my database is "allow read,write: if true", and so Google keeps reminding me to fix this unsecurity. This I did:
- including firebase_auth
- changing my rules on firebase
- creating a mail/password account
- implementing the login procedure
- changing the rules to "allow write: if request.auth != null;"
I think I made everything ok. In the app, it seems so:
print("User ${(await FirebaseAuth.instance.currentUser()).email})");
This gives me the mail of my account. Also I have a onAuthStageChanged listener and I get what I would expect. So I guess the login did work.
But if I try to make a database access e.g. with .setData(), I get an error
W/Firestore( 4411): (19.0.0) [Firestore]: Write failed at...: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
It looked for me as if the auth package is not informing the firestore package correctly. In the logs, I see
D/FirebaseAuth( 5698): Notifying id token listeners about user (...).
I would expect something like "Firestore: received token...", but this does not come.
Do I have to be careful with the initialization order? Mine is
- _app = await Firebase.App.configure...
- _firestore = Firestore(app: _app);
- await FirebaseAuth.instance.signInWithEmailAndPassword...
I tried it on some Samsung and OnePlus devices with Android 8 and 9.
Any hints someone?