Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Random permission errors when logging in with multiple tabs open

オープン
#574 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
firebase, react, typescript

調査の方向性

enableMultiTabIndexedDbPersistence、ブラウザー ローカルの getAuth() 永続化、複数のタブ、およびログイン直後の即時の useFirestoreDoc サブスクリプションを使って失敗を再現します。まず、報告で言及されている ReactFire フックと Suspense observable パスを追跡します。完了条件は、すべてのタブが permission-denied エラーなしで最初のドキュメントを読み込むことです。

索引モデルが issue の本文から書いたものです。

説明

v5
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.
主要言語
TypeScript
スター
3.6k
フォーク
403
平均マージ
5日 1時間
マージ済み PR(30日)
10

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

FirebaseExtended/reactfire のほかの issue

FirebaseExtended/reactfire の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。