-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useDocumentData fails to update when read permission is not longer denied #291
Comments
I think that can be done by writing a query with the ID of the target document as a filter like below.
import {
documentId,
DocumentReference,
query,
setDoc,
where,
} from "firebase/firestore";
import { useCollectionData } from "react-firebase-hooks/firestore";
export const Test = (docRef: DocumentReference) => {
const [docs] = useCollectionData(
query(
docRef.parent,
where(documentId(), "==", docRef.id),
where(documentId(), "!=", "93OE3unhtzLf2buLXF3e" /* fake ID */), // hack from https://stackoverflow.com/q/67556515/7923918
where("isPrivate", "==", false)
)
);
const doc = docs?.[0];
return (
<>
<p>{JSON.stringify(doc) ?? "loading"}</p>
<button onClick={() => void setDoc(docRef, { isPrivate: false })}>
update
</button>
</>
);
}; |
I think it's because of the To overcome this issue, you can do something like this:
This will change your query depending on the firestore change and reload fetching Otherwise, you can use
You can read more about Hopefully this helps |
I'm using
useDocumentData
in order to fetch a document and keep it updated.When the hook is initialized, reading the doc is not permitted yet (due to a certain condition in the Firestore Security Rules not being met), therefor the read fails with
FirebaseError: Missing or insufficient permissions.
However, after a few minutes there is a change in the database and the document can be read successfully.
If I refresh the page it works properly - otherwise the hook does not automatically update.
How can I fix that? I need it to automatically detect that there are permissions to read this document and keep me up to date with its data.
The text was updated successfully, but these errors were encountered: