Random permission errors when logging in with multiple tabs open
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- firebase, react, typescript
- Bereich
- authentication, database, frontend
Rechercherichtung
Reproduziere den Fehler mit enableMultiTabIndexedDbPersistence, der browserlokalen getAuth()-Persistenz, mehreren Tabs und einem unmittelbaren useFirestoreDoc-Abonnement nach dem Login. Beginne damit, die im Bericht erwähnten ReactFire-Hooks und den Suspense-Observable-Pfad nachzuverfolgen; abgeschlossen ist die Aufgabe, wenn alle Tabs das erste Dokument ohne einen permission-denied-Fehler laden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 3.6k
- Forks
- 403
- Ø Merge
- 5 T. 1 Std.
- Gemergte PRs (30 T.)
- 10
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus FirebaseExtended/reactfire
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 38/100
FirebaseExtended/reactfire#801 ·
-
v5
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
FirebaseExtended/reactfire#793 ·
-
v5
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
FirebaseExtended/reactfire#790 · 2 Kommentare ·
-
v5
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 55/100
FirebaseExtended/reactfire#789 ·
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
FirebaseExtended/reactfire#788 ·
Alle Issues in FirebaseExtended/reactfire
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
bcgov/bc-wallet-mobile#4761 · 1 Kommentar ·
-
external-issue to-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
area-deployment area-integrations triage:bot-seen
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 86/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
refactor
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100