React Firestore Hooks still fail to update when read permission is granted
P粉763662390
P粉763662390 2023-09-09 21:52:30
0
1
508

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粉763662390
P粉763662390

reply all(1)
P粉970736384

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.
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template