Random permission errors when logging in with multiple tabs open
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Stack technique
- firebase, react, typescript
- Domaine
- authentication, database, frontend
Piste de recherche
Reproduisez l’échec avec enableMultiTabIndexedDbPersistence, la persistance getAuth() locale au navigateur, plusieurs onglets et un abonnement immédiat à useFirestoreDoc après la connexion. Commencez par suivre les hooks ReactFire et le chemin de l’observable Suspense mentionnés dans le rapport ; c’est terminé lorsque tous les onglets chargent le premier document sans erreur permission-denied.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Version info
React: 18.2.0
Firebase: 9.15.0
ReactFire: 4.2.2
Other (e.g. Node, browser, operating system) (if applicable):
Node: 18.4.0
Test case
When you have multi-tab persistence enabled (enableMultiTabIndexedDbPersistence) and you use the default auth persistence mode from getAuth() (browser local persistence), and your firebase app is open in multiple tabs, it occasionally fails to load the first requested document with a code=permission-denied error:
FirebaseError: [code=permission-denied]: Missing or insufficient permissions.
Here's a short video demonstrating the problem:
https://user-images.githubusercontent.com/307312/210944853-38bfaf81-dc8e-4627-a29d-c2b31ac4f0a9.mp4
When the tab where the error occurred is reloaded the app loads just fine. The symptoms are very similar to those described in https://github.com/FirebaseExtended/reactfire/issues/485 and https://github.com/FirebaseExtended/reactfire/discussions/228, but the workaround of clearing the observables cache does not prevent this issue from occurring. The problem I'm having here sounds identical to https://github.com/firebase/firebase-js-sdk/issues/1981, but when I try loading the user document with the vanilla firebase SDK I actually don't get any permissions errors. It only happens when using the reactfire hooks.
Unfortunately, due to https://github.com/FirebaseExtended/reactfire/issues/540 it's impossible to catch the permissions error and deal with it, so I've had to resort to a really ugly hack where I inspect the preloaded observables cache, find the observable associated with my user document, and check if ourError contains a permission-denied error. If it does, I force the window to reload. It's not ideal because the error boundary still flashes for a second, and the error ends up in the console, but it's better than failing to load the app entirely. Here's what the workaround looks like:
// In some functional component:
applyReactfireWorkaround(`:users/${authUser.data.uid}`);
const user = useFirestoreDoc(...);
function applyReactfireWorkaround(...keySubstrings: string[]): void {
const reactFirePreloadedObservables = (globalThis as Record<string, unknown>)['_reactFirePreloadedObservables'] as
| Map<string, unknown>
| undefined;
if (reactFirePreloadedObservables) {
const hasPermissionDeniedError = Array.from(reactFirePreloadedObservables.keys())
.filter((key) => key.startsWith('firestore:'))
.filter((key) => keySubstrings.every((substring) => key.includes(substring)))
.map((key) => reactFirePreloadedObservables.get(key) as SuspenseSubject<unknown>)
.some((subject) => (subject.ourError as FirebaseError | undefined)?.code === 'permission-denied');
if (hasPermissionDeniedError) {
globalThis.location.reload();
}
}
}
Steps to reproduce
Log in and out of a Firebase app with multi-tab persistence enabled and browser local auth. A document subscription should be made immediately after logging in, e.g. to a document representing the current user.
Expected behavior
All tabs load successfully.
Actual behavior
One or more tabs blow up when accessing the first document with useFirestoreDoc with the following error:
FirebaseError: [code=permission-denied]: Missing or insufficient permissions.
- Langage dominant
- TypeScript
- Étoiles
- 3.6k
- Forks
- 403
- Merge moyen
- 5 j 1 h
- PR mergées (30 j)
- 10
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de FirebaseExtended/reactfire
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 38/100
FirebaseExtended/reactfire#801 ·
-
v5
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
FirebaseExtended/reactfire#793 ·
-
v5
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
FirebaseExtended/reactfire#790 · 2 commentaires ·
-
v5
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
FirebaseExtended/reactfire#789 ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
FirebaseExtended/reactfire#788 ·
Toutes les issues de FirebaseExtended/reactfire
Issues similaires
-
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
motiondivision/motion#3849 ·
-
Add: S Play Event HD Ouvertecheck:passed streams:add
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
Improvement for contact popover Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
LiteLLM proxy response_cost (x-litellm-response-cost) is never applied to ChatModelOutput.cost Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
i-am-bee/beeai-framework#1697 · 1 réaction ·
-
Support bun dedupe Ouverteenhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
antfu/node-modules-inspector#214 ·