0

I use Flutter, Timer and Firebase/Firestore.batch to do something like this sample code to save data periodically on Mac. https://github.com/tomoyuki28jp/flutterfire_scheduled_batch_write_sample2

When I run my app for few days, I get this error randomly:

flutter: [cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.
flutter:
#0      MethodChannelWriteBatch.commit
package:cloud_firestore_platform_interface/…/method_channel/method_channel_write_batch.dart:51
<asynchronous suspension>
  • After hot reloading, it start working again.
  • Background task keep throwing this error until restarting or reloading my app
  • While a background task is throwing this error, I can still successfully save firestore data by using my app UI manually.

How can I investigate the cause?

Tom
  • 478
  • 1
  • 6
  • 17
  • Does this answer your question? [Sign out error Cloud Firestore. The caller does not have permission to execute the specified operation](https://stackoverflow.com/questions/64922374/sign-out-error-cloud-firestore-the-caller-does-not-have-permission-to-execute-t) – Roger May 21 '21 at 14:48
  • 1
    Please include the code you're having difficulty with in the question. If you delete that link in the future, it would make the question useless to future readers. Please take a moment and review [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Jay May 21 '21 at 17:44
  • @Roger Thanks for your comment. Unfortunately, no :( – Tom May 24 '21 at 05:23
  • Have you figured out a solution? I'm having this issue as well. – 31Carlton7 Jul 29 '21 at 14:34
  • @31Carlton7 Unfortunately, no :( I've been struggling for a long time. If you figure out a solution, please let me know. If you can create a sample code which reproduce the issue, please open a github issue and let me know. – Tom Jul 30 '21 at 22:47
  • @Tom I wonder why firestore can't do a query like this. For a company like Google, I'm surprised that there's only 8-10 querying methods. I had to restructure my code in the end, and I'm having to store duplicate data inside the database. This should be addressed. – 31Carlton7 Jul 31 '21 at 18:45
  • I've created a github issue. https://github.com/FirebaseExtended/flutterfire/issues/6898 – Tom Aug 27 '21 at 08:56

1 Answers1

0

User credentials do expire over time - hot reloading likely re-establishes the Auth session. It is known that Auth needs to be re-established periodically - Firestore is NOT really intended as a permanent connection. Your code needs to be able to respond to changes in Auth state (there is a library function to Listen to Auth events), and respond accordingly - including re-authorizing if that's your intent.

LeadDreamer
  • 3,303
  • 2
  • 15
  • 18
  • Thanks for your answer. I know firebase tokens are valid only for one hour. But the wired thing is the error occurs randomly sometimes later like few days after starting my app. – Tom May 20 '21 at 05:38