question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useFirestoreDocData & useFirestoreDoc won't throw a promise on permission denied

See original GitHub issue

Version info

React: 16.12.0

Firebase: 7.5.2

ReactFire: 2.0.0-canary.1fce6b9

Test case

I want to use role based authentication on documents, so when a document is successfully read in the app and then I change the access of that user, the listener throws an error instead of a Promise.

const CompanyCheck: React.FC = ({ children }) => {
  const { companyId, setCompany } = useCompanyContext();

  const firestore: Firebase['Firestore'] = useFirestore();

  const companyRef = useRef(
    firestore()
      .collection('companies')
      .doc(companyId)
  );

  useEffect(() => {
    companyRef.current = firestore()
      .collection('companies')
      .doc(companyId);
  }, [companyId, firestore]);

  // This won't throw a promise on permission changes after successfull read.
  const companyDoc = useFirestoreDocData<Company>(companyRef.current);

  useEffect(() => {
    setCompany(companyDoc);
  }, [companyDoc, setCompany]);

  return <>{children}</>;
};

Steps to reproduce

Use a correct example of read operation with role access, then once the data is displayed remove the access to the document and error boundary won’t catch any error.

Expected behavior

Throw a promise like when initial read fails so ErrorBoundary can catch the error.

Actual behavior

Don’t throw a Promise and error can’t be handled. Error message is: ‘permission-denied’

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
RodyGLcommented, Dec 10, 2019

That’s what I meant. After changing the access an error is triggered due to permission denied but the Error Boundary is not catching any error and because of that the fallback is not showing.

0reactions
RodyGLcommented, Dec 10, 2019

Thanks a lot for your reply and effort @jhuleatt. I apologize if I wasn’t clear enough with the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the proper way to handle "Permission Denied" when a ...
I have written rules for Firestore, however, when a document does not exist it throws a "Missing or Insufficient Permissions error".
Read more >
How to fix Firestore Error: PERMISSION_DENIED - Medium
The caller does not have permission to execute the specified ... the above Exception is thrown containing the following error message:.
Read more >
cloud_firestore/permission-denied flutter - You.com | The AI ...
Describe the bug I can't get access to Cloud Firestore database for my Web application. It throws me an error [cloud_firestore/permission-denied] Missing or ......
Read more >
Permission Denied in Firestore - Anycodings.com
In the future, anycodings_firebase-security promise rejections that are not handled will anycodings_firebase-security terminate the Node.js ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found