I'm using react-firebase-hooks, specifically useDocumentData, in order to get the document and keep it updated.
When the hook initializes, reading the document is not yet allowed (due to a certain condition in the Firestore security rules not being met), so the read fails with FirebaseError: Missing or insufficient permissions.
However, after a few minutes the database changed and the document could be read successfully.
If I refresh the page it works fine - Otherwise the hook doesn't update automatically.
How can I solve this problem? I need it to automatically detect permission to read this document and update its data at any time.
You can't accomplish this without querying it yourself. Once a query listener fails due to a permission error, it will not continue to listen. There is no callback to tell you when queries can be allowed again.
You can choose one of the following two methods: