search

Home  >  Q&A  >  body text

React Firestore Hooks still fail to update when read permission is granted

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.

P粉763662390P粉763662390476 days ago519

reply all(1)I'll reply

  • P粉970736384

    P粉9707363842023-09-10 17:13:17

    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:

    1. Set up another query listener for the changed data to allow the original query to work, then reissue the original query.
    2. Or you need to periodically poll the query to find if it is working.

    reply
    0
  • Cancelreply