You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a document ID which is parsed from a URL query. That means that it could be invalid or point to a document that a user doesn't have security rule permissions to read. My solution for this right now is to catch errors when loading the document:
I'd like to switch to using useFirestoreDocData because of the very simple API for realtime updates and the efficient caching of listeners. I was hoping that the returned status field would be useful for indentifying cases where the document isn't available (e.g. invalid ID or missing permissions). This is what I wrote:
const { status, data } = useFirestoreDocData(doc(db, 'Collection', documentId));
if (status === 'loading') {
// handle loading
} else if (status === 'error') {
// handle errors
} else {
// display the document
}
This doesn't work and instead I get an uncaught missing permissions error (including for an invalid document ID). So I have two questions I think:
What is status === 'error' supposed to be used for? I couldn't see anything in the docs or other discussions/issues.
What is the best way to deal with document reads which may fail? I think I could create an error boundary to catch the error but for my use case that's more boilerplate than just not using reactfire.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi folks,
I have a document ID which is parsed from a URL query. That means that it could be invalid or point to a document that a user doesn't have security rule permissions to read. My solution for this right now is to catch errors when loading the document:
getDoc(doc(db, "Collection", documentId)).catch((error) => handle(error));
I'd like to switch to using useFirestoreDocData because of the very simple API for realtime updates and the efficient caching of listeners. I was hoping that the returned status field would be useful for indentifying cases where the document isn't available (e.g. invalid ID or missing permissions). This is what I wrote:
This doesn't work and instead I get an uncaught missing permissions error (including for an invalid document ID). So I have two questions I think:
Thanks a lot : )
Beta Was this translation helpful? Give feedback.
All reactions