@firebase/auth 1.13.9 → 1.13.10-20261111165442

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/auth-public.d.ts +1 -0
  2. package/dist/auth.d.ts +1 -0
  3. package/dist/browser-cjs/{index-DTUcAMkM.js → index-3quNI-5T.js} +180 -62
  4. package/dist/browser-cjs/index-3quNI-5T.js.map +1 -0
  5. package/dist/browser-cjs/index.js +1 -1
  6. package/dist/browser-cjs/internal.js +1 -1
  7. package/dist/browser-cjs/src/core/persistence/index.d.ts +1 -0
  8. package/dist/browser-cjs/src/platform_browser/persistence/indexed_db.d.ts +18 -4
  9. package/dist/cordova/auth-cordova-public.d.ts +1 -0
  10. package/dist/cordova/auth-cordova.d.ts +1 -0
  11. package/dist/cordova/index.js +2 -2
  12. package/dist/cordova/internal.js +2 -2
  13. package/dist/cordova/{popup_redirect-xyFFcAgj.js → popup_redirect-BfyV9XtN.js} +180 -62
  14. package/dist/cordova/popup_redirect-BfyV9XtN.js.map +1 -0
  15. package/dist/cordova/src/core/persistence/index.d.ts +1 -0
  16. package/dist/cordova/src/platform_browser/persistence/indexed_db.d.ts +18 -4
  17. package/dist/esm/{index-Bz2J43nW.js → index-D7PwIQ8t.js} +180 -62
  18. package/dist/esm/index-D7PwIQ8t.js.map +1 -0
  19. package/dist/esm/index.js +1 -1
  20. package/dist/esm/internal.js +2 -2
  21. package/dist/esm/src/core/persistence/index.d.ts +1 -0
  22. package/dist/esm/src/platform_browser/persistence/indexed_db.d.ts +18 -4
  23. package/dist/index.webworker.js +179 -61
  24. package/dist/index.webworker.js.map +1 -1
  25. package/dist/node/index.js +1 -1
  26. package/dist/node/internal.js +1 -1
  27. package/dist/node/internal.js.map +1 -1
  28. package/dist/node/src/core/persistence/index.d.ts +1 -0
  29. package/dist/node/src/platform_browser/persistence/indexed_db.d.ts +18 -4
  30. package/dist/node/{totp-CMTC0AYP.js → totp-Cvunw6R9.js} +49 -30
  31. package/dist/node/totp-Cvunw6R9.js.map +1 -0
  32. package/dist/node-esm/index.js +1 -1
  33. package/dist/node-esm/internal.js +2 -2
  34. package/dist/node-esm/internal.js.map +1 -1
  35. package/dist/node-esm/src/core/persistence/index.d.ts +1 -0
  36. package/dist/node-esm/src/platform_browser/persistence/indexed_db.d.ts +18 -4
  37. package/dist/node-esm/{totp-pe8Y0u5S.js → totp-BIzof36h.js} +49 -30
  38. package/dist/node-esm/totp-BIzof36h.js.map +1 -0
  39. package/dist/rn/{index-DzY9h3Kn.js → index-Cjrvemz_.js} +49 -30
  40. package/dist/rn/index-Cjrvemz_.js.map +1 -0
  41. package/dist/rn/index.js +1 -1
  42. package/dist/rn/internal.js +132 -33
  43. package/dist/rn/internal.js.map +1 -1
  44. package/dist/rn/src/core/persistence/index.d.ts +1 -0
  45. package/dist/rn/src/platform_browser/persistence/indexed_db.d.ts +18 -4
  46. package/dist/src/core/persistence/index.d.ts +1 -0
  47. package/dist/src/platform_browser/persistence/indexed_db.d.ts +18 -4
  48. package/dist/web-extension-cjs/index.js +1 -1
  49. package/dist/web-extension-cjs/internal.js +1 -1
  50. package/dist/web-extension-cjs/{register-CTiLN4Sf.js → register-Bj5RraXk.js} +180 -62
  51. package/dist/web-extension-cjs/register-Bj5RraXk.js.map +1 -0
  52. package/dist/web-extension-cjs/src/core/persistence/index.d.ts +1 -0
  53. package/dist/web-extension-cjs/src/platform_browser/persistence/indexed_db.d.ts +18 -4
  54. package/dist/web-extension-esm/auth-web-extension-public.d.ts +1 -0
  55. package/dist/web-extension-esm/auth-web-extension.d.ts +1 -0
  56. package/dist/web-extension-esm/index.js +2 -2
  57. package/dist/web-extension-esm/internal.js +2 -2
  58. package/dist/web-extension-esm/{register-DBjcU-NC.js → register-B2Dp0WV3.js} +180 -62
  59. package/dist/web-extension-esm/register-B2Dp0WV3.js.map +1 -0
  60. package/dist/web-extension-esm/src/core/persistence/index.d.ts +1 -0
  61. package/dist/web-extension-esm/src/platform_browser/persistence/indexed_db.d.ts +18 -4
  62. package/package.json +1 -1
  63. package/dist/browser-cjs/index-DTUcAMkM.js.map +0 -1
  64. package/dist/cordova/popup_redirect-xyFFcAgj.js.map +0 -1
  65. package/dist/esm/index-Bz2J43nW.js.map +0 -1
  66. package/dist/node/totp-CMTC0AYP.js.map +0 -1
  67. package/dist/node-esm/totp-pe8Y0u5S.js.map +0 -1
  68. package/dist/rn/index-DzY9h3Kn.js.map +0 -1
  69. package/dist/web-extension-cjs/register-CTiLN4Sf.js.map +0 -1
  70. package/dist/web-extension-esm/register-DBjcU-NC.js.map +0 -1
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { A as ActionCodeOperation, a as ActionCodeURL, b as AuthCredential, c as AuthErrorCodes, E as EmailAuthCredential, d as EmailAuthProvider, F as FacebookAuthProvider, e as FactorId, G as GithubAuthProvider, f as GoogleAuthProvider, O as OAuthCredential, g as OAuthProvider, h as OperationType, P as PhoneAuthCredential, i as PhoneAuthProvider, j as PhoneMultiFactorGenerator, k as ProviderId, R as RecaptchaVerifier, S as SAMLAuthProvider, l as SignInMethod, T as TotpMultiFactorGenerator, m as TotpSecret, n as TwitterAuthProvider, o as applyActionCode, p as beforeAuthStateChanged, q as browserCookiePersistence, r as browserLocalPersistence, s as browserPopupRedirectResolver, t as browserSessionPersistence, u as checkActionCode, v as confirmPasswordReset, w as connectAuthEmulator, x as createUserWithEmailAndPassword, y as debugErrorMap, z as deleteUser, B as fetchSignInMethodsForEmail, C as getAdditionalUserInfo, D as getAuth, H as getIdToken, I as getIdTokenResult, J as getMultiFactorResolver, K as getRedirectResult, L as inMemoryPersistence, M as indexedDBLocalPersistence, N as initializeAuth, Q as initializeRecaptchaConfig, U as isSignInWithEmailLink, V as linkWithCredential, W as linkWithPhoneNumber, X as linkWithPopup, Y as linkWithRedirect, Z as multiFactor, _ as onAuthStateChanged, $ as onIdTokenChanged, a0 as parseActionCodeURL, a1 as prodErrorMap, a2 as reauthenticateWithCredential, a3 as reauthenticateWithPhoneNumber, a4 as reauthenticateWithPopup, a5 as reauthenticateWithRedirect, a6 as reload, a7 as revokeAccessToken, a8 as sendEmailVerification, a9 as sendPasswordResetEmail, aa as sendSignInLinkToEmail, ab as setPersistence, ac as signInAnonymously, ad as signInWithCredential, ae as signInWithCustomToken, af as signInWithEmailAndPassword, ag as signInWithEmailLink, ah as signInWithPhoneNumber, ai as signInWithPopup, aj as signInWithRedirect, ak as signOut, al as unlink, am as updateCurrentUser, an as updateEmail, ao as updatePassword, ap as updatePhoneNumber, aq as updateProfile, ar as useDeviceLanguage, as as validatePassword, at as verifyBeforeUpdateEmail, au as verifyPasswordResetCode } from './index-Bz2J43nW.js';
1
+ export { A as ActionCodeOperation, a as ActionCodeURL, b as AuthCredential, c as AuthErrorCodes, E as EmailAuthCredential, d as EmailAuthProvider, F as FacebookAuthProvider, e as FactorId, G as GithubAuthProvider, f as GoogleAuthProvider, O as OAuthCredential, g as OAuthProvider, h as OperationType, P as PhoneAuthCredential, i as PhoneAuthProvider, j as PhoneMultiFactorGenerator, k as ProviderId, R as RecaptchaVerifier, S as SAMLAuthProvider, l as SignInMethod, T as TotpMultiFactorGenerator, m as TotpSecret, n as TwitterAuthProvider, o as applyActionCode, p as beforeAuthStateChanged, q as browserCookiePersistence, r as browserLocalPersistence, s as browserPopupRedirectResolver, t as browserSessionPersistence, u as checkActionCode, v as confirmPasswordReset, w as connectAuthEmulator, x as createUserWithEmailAndPassword, y as debugErrorMap, z as deleteUser, B as fetchSignInMethodsForEmail, C as getAdditionalUserInfo, D as getAuth, H as getIdToken, I as getIdTokenResult, J as getMultiFactorResolver, K as getRedirectResult, L as inMemoryPersistence, M as indexedDBLocalPersistence, N as initializeAuth, Q as initializeRecaptchaConfig, U as isSignInWithEmailLink, V as linkWithCredential, W as linkWithPhoneNumber, X as linkWithPopup, Y as linkWithRedirect, Z as multiFactor, _ as onAuthStateChanged, $ as onIdTokenChanged, a0 as parseActionCodeURL, a1 as prodErrorMap, a2 as reauthenticateWithCredential, a3 as reauthenticateWithPhoneNumber, a4 as reauthenticateWithPopup, a5 as reauthenticateWithRedirect, a6 as reload, a7 as revokeAccessToken, a8 as sendEmailVerification, a9 as sendPasswordResetEmail, aa as sendSignInLinkToEmail, ab as setPersistence, ac as signInAnonymously, ad as signInWithCredential, ae as signInWithCustomToken, af as signInWithEmailAndPassword, ag as signInWithEmailLink, ah as signInWithPhoneNumber, ai as signInWithPopup, aj as signInWithRedirect, ak as signOut, al as unlink, am as updateCurrentUser, an as updateEmail, ao as updatePassword, ap as updatePhoneNumber, aq as updateProfile, ar as useDeviceLanguage, as as validatePassword, at as verifyBeforeUpdateEmail, au as verifyPasswordResetCode } from './index-D7PwIQ8t.js';
2
2
  import '@firebase/app';
3
3
  import '@firebase/util';
4
4
  import '@firebase/logger';
@@ -1,5 +1,5 @@
1
- import { av as _assert, aw as debugAssert, ax as _isIOS, ay as _isAndroid, az as _fail, aA as _getRedirectUrl, aB as _isIOS7Or8, aC as _createError, aD as _getProjectConfig, aE as AuthEventManager, aF as _getInstance, r as browserLocalPersistence, aG as _persistenceKeyName, t as browserSessionPersistence, aH as _getRedirectResult, aI as _overrideRedirectResult, aJ as _clearRedirectOutcomes, aK as _castAuth } from './index-Bz2J43nW.js';
2
- export { A as ActionCodeOperation, a as ActionCodeURL, b as AuthCredential, c as AuthErrorCodes, aL as AuthImpl, aM as AuthPopup, E as EmailAuthCredential, d as EmailAuthProvider, F as FacebookAuthProvider, e as FactorId, aN as FetchProvider, G as GithubAuthProvider, f as GoogleAuthProvider, O as OAuthCredential, g as OAuthProvider, h as OperationType, P as PhoneAuthCredential, i as PhoneAuthProvider, j as PhoneMultiFactorGenerator, k as ProviderId, R as RecaptchaVerifier, aO as SAMLAuthCredential, S as SAMLAuthProvider, l as SignInMethod, T as TotpMultiFactorGenerator, m as TotpSecret, n as TwitterAuthProvider, aP as UserImpl, aQ as _generateEventId, aR as _getClientVersion, o as applyActionCode, p as beforeAuthStateChanged, q as browserCookiePersistence, s as browserPopupRedirectResolver, u as checkActionCode, v as confirmPasswordReset, w as connectAuthEmulator, x as createUserWithEmailAndPassword, y as debugErrorMap, z as deleteUser, B as fetchSignInMethodsForEmail, C as getAdditionalUserInfo, D as getAuth, H as getIdToken, I as getIdTokenResult, J as getMultiFactorResolver, K as getRedirectResult, L as inMemoryPersistence, M as indexedDBLocalPersistence, N as initializeAuth, Q as initializeRecaptchaConfig, U as isSignInWithEmailLink, V as linkWithCredential, W as linkWithPhoneNumber, X as linkWithPopup, Y as linkWithRedirect, Z as multiFactor, _ as onAuthStateChanged, $ as onIdTokenChanged, a0 as parseActionCodeURL, a1 as prodErrorMap, a2 as reauthenticateWithCredential, a3 as reauthenticateWithPhoneNumber, a4 as reauthenticateWithPopup, a5 as reauthenticateWithRedirect, a6 as reload, a7 as revokeAccessToken, a8 as sendEmailVerification, a9 as sendPasswordResetEmail, aa as sendSignInLinkToEmail, ab as setPersistence, ac as signInAnonymously, ad as signInWithCredential, ae as signInWithCustomToken, af as signInWithEmailAndPassword, ag as signInWithEmailLink, ah as signInWithPhoneNumber, ai as signInWithPopup, aj as signInWithRedirect, ak as signOut, al as unlink, am as updateCurrentUser, an as updateEmail, ao as updatePassword, ap as updatePhoneNumber, aq as updateProfile, ar as useDeviceLanguage, as as validatePassword, at as verifyBeforeUpdateEmail, au as verifyPasswordResetCode } from './index-Bz2J43nW.js';
1
+ import { av as _assert, aw as debugAssert, ax as _isIOS, ay as _isAndroid, az as _fail, aA as _getRedirectUrl, aB as _isIOS7Or8, aC as _createError, aD as _getProjectConfig, aE as AuthEventManager, aF as _getInstance, r as browserLocalPersistence, aG as _persistenceKeyName, t as browserSessionPersistence, aH as _getRedirectResult, aI as _overrideRedirectResult, aJ as _clearRedirectOutcomes, aK as _castAuth } from './index-D7PwIQ8t.js';
2
+ export { A as ActionCodeOperation, a as ActionCodeURL, b as AuthCredential, c as AuthErrorCodes, aL as AuthImpl, aM as AuthPopup, E as EmailAuthCredential, d as EmailAuthProvider, F as FacebookAuthProvider, e as FactorId, aN as FetchProvider, G as GithubAuthProvider, f as GoogleAuthProvider, O as OAuthCredential, g as OAuthProvider, h as OperationType, P as PhoneAuthCredential, i as PhoneAuthProvider, j as PhoneMultiFactorGenerator, k as ProviderId, R as RecaptchaVerifier, aO as SAMLAuthCredential, S as SAMLAuthProvider, l as SignInMethod, T as TotpMultiFactorGenerator, m as TotpSecret, n as TwitterAuthProvider, aP as UserImpl, aQ as _generateEventId, aR as _getClientVersion, o as applyActionCode, p as beforeAuthStateChanged, q as browserCookiePersistence, s as browserPopupRedirectResolver, u as checkActionCode, v as confirmPasswordReset, w as connectAuthEmulator, x as createUserWithEmailAndPassword, y as debugErrorMap, z as deleteUser, B as fetchSignInMethodsForEmail, C as getAdditionalUserInfo, D as getAuth, H as getIdToken, I as getIdTokenResult, J as getMultiFactorResolver, K as getRedirectResult, L as inMemoryPersistence, M as indexedDBLocalPersistence, N as initializeAuth, Q as initializeRecaptchaConfig, U as isSignInWithEmailLink, V as linkWithCredential, W as linkWithPhoneNumber, X as linkWithPopup, Y as linkWithRedirect, Z as multiFactor, _ as onAuthStateChanged, $ as onIdTokenChanged, a0 as parseActionCodeURL, a1 as prodErrorMap, a2 as reauthenticateWithCredential, a3 as reauthenticateWithPhoneNumber, a4 as reauthenticateWithPopup, a5 as reauthenticateWithRedirect, a6 as reload, a7 as revokeAccessToken, a8 as sendEmailVerification, a9 as sendPasswordResetEmail, aa as sendSignInLinkToEmail, ab as setPersistence, ac as signInAnonymously, ad as signInWithCredential, ae as signInWithCustomToken, af as signInWithEmailAndPassword, ag as signInWithEmailLink, ah as signInWithPhoneNumber, ai as signInWithPopup, aj as signInWithRedirect, ak as signOut, al as unlink, am as updateCurrentUser, an as updateEmail, ao as updatePassword, ap as updatePhoneNumber, aq as updateProfile, ar as useDeviceLanguage, as as validatePassword, at as verifyBeforeUpdateEmail, au as verifyPasswordResetCode } from './index-D7PwIQ8t.js';
3
3
  import { querystringDecode } from '@firebase/util';
4
4
  import '@firebase/app';
5
5
  import '@firebase/logger';
@@ -39,4 +39,5 @@ export interface PersistenceInternal extends Persistence {
39
39
  _addListener(key: string, listener: StorageEventListener): void;
40
40
  _removeListener(key: string, listener: StorageEventListener): void;
41
41
  _shouldAllowMigration?: boolean;
42
+ _lastProbeTimedOut?: boolean;
42
43
  }
@@ -17,13 +17,27 @@
17
17
  import { Persistence } from '../../model/public_types';
18
18
  import { PersistenceValue } from '../../core/persistence/';
19
19
  export declare const DB_NAME = "firebaseLocalStorageDb";
20
+ export declare const _POLLING_INTERVAL_MS = 800;
21
+ export declare const _TRANSACTION_RETRY_COUNT = 3;
22
+ /**
23
+ * Short timeout scoped to the `readwrite` availability probe in `_isAvailable()`.
24
+ * Matches `_POLLING_INTERVAL_MS` so that if a background tab is suspended while
25
+ * holding a `readonly` poll transaction that blocks `readwrite` transactions
26
+ * (#10540), the startup probe fails fast and aborts its queued transaction in
27
+ * under a second without blocking fallback or user loading.
28
+ */
29
+ export declare const _DB_PROBE_TIMEOUT_MS = 800;
30
+ /**
31
+ * Timeout for opening the database and regular IndexedDB read/write requests.
32
+ * Kept at multiple seconds to accommodate cold `indexedDB.open()` or slow disk
33
+ * I/O on low-end devices without premature timeouts.
34
+ */
35
+ export declare const _DB_TIMEOUT_MS = 2500;
20
36
  export declare function _clearDatabase(db: IDBDatabase): Promise<void>;
21
37
  export declare function _deleteDatabase(): Promise<void>;
22
38
  export declare function _openDatabase(): Promise<IDBDatabase>;
23
- export declare function _putObject(db: IDBDatabase, key: string, value: PersistenceValue | string): Promise<void>;
24
- export declare function _deleteObject(db: IDBDatabase, key: string): Promise<void>;
25
- export declare const _POLLING_INTERVAL_MS = 800;
26
- export declare const _TRANSACTION_RETRY_COUNT = 3;
39
+ export declare function _putObject(db: IDBDatabase, key: string, value: PersistenceValue | string, timeoutMs?: number): Promise<void>;
40
+ export declare function _deleteObject(db: IDBDatabase, key: string, timeoutMs?: number): Promise<void>;
27
41
  /**
28
42
  * An implementation of {@link Persistence} of type `LOCAL` using `indexedDB`
29
43
  * for the underlying storage.
@@ -533,7 +533,7 @@ function _initializeAuthInstance(auth, deps) {
533
533
  }
534
534
 
535
535
  var name = "@firebase/auth";
536
- var version = "1.13.9";
536
+ var version = "1.13.10-20261111165442";
537
537
 
538
538
  /**
539
539
  * @license
@@ -2135,31 +2135,25 @@ class PersistenceUserManager {
2135
2135
  if (!persistenceHierarchy.length) {
2136
2136
  return new PersistenceUserManager(_getInstance(inMemoryPersistence), auth, userKey);
2137
2137
  }
2138
- // Eliminate any persistences that are not available
2139
- const availablePersistences = (await Promise.all(persistenceHierarchy.map(async (persistence) => {
2138
+ const key = _persistenceKeyName(userKey, auth.config.apiKey, auth.name);
2139
+ // Search for an existing user across all persistences before running `_isAvailable()`.
2140
+ // `_get` only opens a `readonly` transaction in IndexedDB, whereas `_isAvailable()` opens
2141
+ // a `readwrite` transaction; if another tab is suspended holding a `readonly` transaction
2142
+ // (#10540), queuing a `readwrite` transaction first blocks subsequent `readonly` transactions
2143
+ // in the browser's IndexedDB lock manager.
2144
+ let foundUser = null;
2145
+ let foundPersistence = null;
2146
+ const unreadablePersistences = new Set();
2147
+ for (const persistence of persistenceHierarchy) {
2148
+ let blob = null;
2140
2149
  try {
2141
- if (await persistence._isAvailable()) {
2142
- return persistence;
2143
- }
2150
+ blob = await persistence._get(key);
2144
2151
  }
2145
2152
  catch {
2146
- return undefined;
2153
+ unreadablePersistences.add(persistence);
2154
+ continue;
2147
2155
  }
2148
- return undefined;
2149
- }))).filter(persistence => persistence);
2150
- // Fall back to the first persistence listed, or in memory if none available
2151
- let selectedPersistence = availablePersistences[0] ||
2152
- _getInstance(inMemoryPersistence);
2153
- const key = _persistenceKeyName(userKey, auth.config.apiKey, auth.name);
2154
- // Pull out the existing user, setting the chosen persistence to that
2155
- // persistence if the user exists.
2156
- let userToMigrate = null;
2157
- // Note, here we check for a user in _all_ persistences, not just the
2158
- // ones deemed available. If we can migrate a user out of a broken
2159
- // persistence, we will (but only if that persistence supports migration).
2160
- for (const persistence of persistenceHierarchy) {
2161
2156
  try {
2162
- const blob = await persistence._get(key);
2163
2157
  if (blob) {
2164
2158
  let user;
2165
2159
  if (typeof blob === 'string') {
@@ -2174,15 +2168,38 @@ class PersistenceUserManager {
2174
2168
  else {
2175
2169
  user = UserImpl._fromJSON(auth, blob); // throws for unparsable blob (wrong format)
2176
2170
  }
2177
- if (persistence !== selectedPersistence) {
2178
- userToMigrate = user;
2179
- }
2180
- selectedPersistence = persistence;
2171
+ foundUser = user;
2172
+ foundPersistence = persistence;
2181
2173
  break;
2182
2174
  }
2183
2175
  }
2184
2176
  catch { }
2185
2177
  }
2178
+ // Eliminate any persistences that are not available
2179
+ const availablePersistences = (await Promise.all(persistenceHierarchy.map(async (persistence) => {
2180
+ try {
2181
+ if (await persistence._isAvailable()) {
2182
+ return persistence;
2183
+ }
2184
+ if (persistence._lastProbeTimedOut) {
2185
+ unreadablePersistences.add(persistence);
2186
+ }
2187
+ }
2188
+ catch {
2189
+ return undefined;
2190
+ }
2191
+ return undefined;
2192
+ }))).filter(persistence => persistence);
2193
+ // Fall back to the first persistence listed, or in memory if none available
2194
+ let selectedPersistence = availablePersistences[0] ||
2195
+ _getInstance(inMemoryPersistence);
2196
+ let userToMigrate = null;
2197
+ if (foundPersistence && foundUser) {
2198
+ if (foundPersistence !== selectedPersistence) {
2199
+ userToMigrate = foundUser;
2200
+ }
2201
+ selectedPersistence = foundPersistence;
2202
+ }
2186
2203
  // If we find the user in a persistence that does support migration, use
2187
2204
  // that migration path (of only persistences that support migration)
2188
2205
  const migrationHierarchy = availablePersistences.filter(p => p._shouldAllowMigration);
@@ -2197,10 +2214,13 @@ class PersistenceUserManager {
2197
2214
  // we'll just let it bubble to surface the error.
2198
2215
  await selectedPersistence._set(key, userToMigrate.toJSON());
2199
2216
  }
2200
- // Attempt to clear the key in other persistences but ignore errors. This helps prevent issues
2201
- // such as users getting stuck with a previous account after signing out and refreshing the tab.
2217
+ // Attempt to clear the key in other persistences (except those whose _get threw or whose
2218
+ // _isAvailable() probe timed out, so we never delete from a store we couldn't read or that
2219
+ // is blocked by another tab) and ignore errors. This helps prevent issues such as users
2220
+ // getting stuck with a previous account after signing out and refreshing the tab.
2202
2221
  await Promise.all(persistenceHierarchy.map(async (persistence) => {
2203
- if (persistence !== selectedPersistence) {
2222
+ if (persistence !== selectedPersistence &&
2223
+ !unreadablePersistences.has(persistence)) {
2204
2224
  try {
2205
2225
  await persistence._remove(key);
2206
2226
  }
@@ -2563,7 +2583,6 @@ class AuthImpl {
2563
2583
  }
2564
2584
  catch (e) {
2565
2585
  _logWarn(`Failed to initialize current user: ${e}`);
2566
- await this.directlySetCurrentUser(null).catch(() => { });
2567
2586
  }
2568
2587
  this.lastNotifiedUid = this.currentUser?.uid || null;
2569
2588
  if (this._deleted) {
@@ -3629,6 +3648,23 @@ const DB_NAME = 'firebaseLocalStorageDb';
3629
3648
  const DB_VERSION = 1;
3630
3649
  const DB_OBJECTSTORE_NAME = 'firebaseLocalStorage';
3631
3650
  const DB_DATA_KEYPATH = 'fbase_key';
3651
+ const _POLLING_INTERVAL_MS = 800;
3652
+ const _TRANSACTION_RETRY_COUNT = 3;
3653
+ /**
3654
+ * Short timeout scoped to the `readwrite` availability probe in `_isAvailable()`.
3655
+ * Matches `_POLLING_INTERVAL_MS` so that if a background tab is suspended while
3656
+ * holding a `readonly` poll transaction that blocks `readwrite` transactions
3657
+ * (#10540), the startup probe fails fast and aborts its queued transaction in
3658
+ * under a second without blocking fallback or user loading.
3659
+ */
3660
+ const _DB_PROBE_TIMEOUT_MS = 800;
3661
+ /**
3662
+ * Timeout for opening the database and regular IndexedDB read/write requests.
3663
+ * Kept at multiple seconds to accommodate cold `indexedDB.open()` or slow disk
3664
+ * I/O on low-end devices without premature timeouts.
3665
+ */
3666
+ const _DB_TIMEOUT_MS = 2500;
3667
+ const DB_TIMEOUT_ERROR = 'DB_TIMEOUT';
3632
3668
  /**
3633
3669
  * Promise wrapper for IDBRequest
3634
3670
  *
@@ -3639,13 +3675,32 @@ class DBPromise {
3639
3675
  constructor(request) {
3640
3676
  this.request = request;
3641
3677
  }
3642
- toPromise() {
3678
+ toPromise(timeoutMs = _DB_TIMEOUT_MS) {
3643
3679
  return new Promise((resolve, reject) => {
3680
+ let settled = false;
3681
+ const timer = setTimeout(() => {
3682
+ if (!settled) {
3683
+ settled = true;
3684
+ try {
3685
+ this.request.transaction?.abort();
3686
+ }
3687
+ catch { }
3688
+ reject(new Error(DB_TIMEOUT_ERROR));
3689
+ }
3690
+ }, timeoutMs);
3644
3691
  this.request.addEventListener('success', () => {
3645
- resolve(this.request.result);
3692
+ if (!settled) {
3693
+ settled = true;
3694
+ clearTimeout(timer);
3695
+ resolve(this.request.result);
3696
+ }
3646
3697
  });
3647
3698
  this.request.addEventListener('error', () => {
3648
- reject(this.request.error);
3699
+ if (!settled) {
3700
+ settled = true;
3701
+ clearTimeout(timer);
3702
+ reject(this.request.error);
3703
+ }
3649
3704
  });
3650
3705
  });
3651
3706
  }
@@ -3662,8 +3717,19 @@ function _deleteDatabase() {
3662
3717
  function _openDatabase() {
3663
3718
  const request = indexedDB.open(DB_NAME, DB_VERSION);
3664
3719
  return new Promise((resolve, reject) => {
3720
+ let settled = false;
3721
+ const timer = setTimeout(() => {
3722
+ if (!settled) {
3723
+ settled = true;
3724
+ reject(new Error(DB_TIMEOUT_ERROR));
3725
+ }
3726
+ }, _DB_TIMEOUT_MS);
3665
3727
  request.addEventListener('error', () => {
3666
- reject(request.error);
3728
+ if (!settled) {
3729
+ settled = true;
3730
+ clearTimeout(timer);
3731
+ reject(request.error);
3732
+ }
3667
3733
  });
3668
3734
  request.addEventListener('upgradeneeded', () => {
3669
3735
  const db = request.result;
@@ -3671,11 +3737,20 @@ function _openDatabase() {
3671
3737
  db.createObjectStore(DB_OBJECTSTORE_NAME, { keyPath: DB_DATA_KEYPATH });
3672
3738
  }
3673
3739
  catch (e) {
3674
- reject(e);
3740
+ if (!settled) {
3741
+ settled = true;
3742
+ clearTimeout(timer);
3743
+ reject(e);
3744
+ }
3675
3745
  }
3676
3746
  });
3677
3747
  request.addEventListener('success', async () => {
3678
3748
  const db = request.result;
3749
+ if (settled) {
3750
+ db.close();
3751
+ return;
3752
+ }
3753
+ clearTimeout(timer);
3679
3754
  // Strange bug that occurs in Firefox when multiple tabs are opened at the
3680
3755
  // same time. The only way to recover seems to be deleting the database
3681
3756
  // and re-initializing it.
@@ -3683,33 +3758,45 @@ function _openDatabase() {
3683
3758
  if (!db.objectStoreNames.contains(DB_OBJECTSTORE_NAME)) {
3684
3759
  // Need to close the database or else you get a `blocked` event
3685
3760
  db.close();
3686
- await _deleteDatabase();
3687
- resolve(await _openDatabase());
3761
+ try {
3762
+ // Note: if `deleteDatabase` is `blocked` by another tab's open connection and
3763
+ // times out (`DB_TIMEOUT_ERROR`), `request.transaction` is null so the browser
3764
+ // keeps the delete request queued until all blocking connections close.
3765
+ await _deleteDatabase();
3766
+ const reopenedDb = await _openDatabase();
3767
+ settled = true;
3768
+ resolve(reopenedDb);
3769
+ }
3770
+ catch (e) {
3771
+ if (!settled) {
3772
+ settled = true;
3773
+ reject(e);
3774
+ }
3775
+ }
3688
3776
  }
3689
3777
  else {
3778
+ settled = true;
3690
3779
  resolve(db);
3691
3780
  }
3692
3781
  });
3693
3782
  });
3694
3783
  }
3695
- async function _putObject(db, key, value) {
3784
+ async function _putObject(db, key, value, timeoutMs = _DB_TIMEOUT_MS) {
3696
3785
  const request = getObjectStore(db, true).put({
3697
3786
  [DB_DATA_KEYPATH]: key,
3698
3787
  value
3699
3788
  });
3700
- return new DBPromise(request).toPromise();
3789
+ return new DBPromise(request).toPromise(timeoutMs);
3701
3790
  }
3702
3791
  async function getObject(db, key) {
3703
3792
  const request = getObjectStore(db, false).get(key);
3704
3793
  const data = await new DBPromise(request).toPromise();
3705
3794
  return data === undefined ? null : data.value;
3706
3795
  }
3707
- function _deleteObject(db, key) {
3796
+ function _deleteObject(db, key, timeoutMs = _DB_TIMEOUT_MS) {
3708
3797
  const request = getObjectStore(db, true).delete(key);
3709
- return new DBPromise(request).toPromise();
3798
+ return new DBPromise(request).toPromise(timeoutMs);
3710
3799
  }
3711
- const _POLLING_INTERVAL_MS = 800;
3712
- const _TRANSACTION_RETRY_COUNT = 3;
3713
3800
  class IndexedDBLocalPersistence {
3714
3801
  registerLifecycleListeners() {
3715
3802
  if (typeof window !== 'undefined' &&
@@ -3736,6 +3823,7 @@ class IndexedDBLocalPersistence {
3736
3823
  this.pollTimer = null;
3737
3824
  this.isClosing = false;
3738
3825
  this.pendingWrites = 0;
3826
+ this._lastProbeTimedOut = false;
3739
3827
  this.receiver = null;
3740
3828
  this.sender = null;
3741
3829
  this.serviceWorkerReceiverAvailable = false;
@@ -3764,32 +3852,46 @@ class IndexedDBLocalPersistence {
3764
3852
  if (this.dbPromise) {
3765
3853
  return this.dbPromise;
3766
3854
  }
3767
- this.dbPromise = _openDatabase();
3768
- this.dbPromise.catch(() => {
3769
- this.dbPromise = null;
3855
+ const dbPromise = _openDatabase();
3856
+ this.dbPromise = dbPromise;
3857
+ dbPromise.catch(() => {
3858
+ if (this.dbPromise === dbPromise) {
3859
+ this.dbPromise = null;
3860
+ }
3770
3861
  });
3771
- return this.dbPromise;
3862
+ return dbPromise;
3772
3863
  }
3773
3864
  async _withRetries(op) {
3774
3865
  let numAttempts = 0;
3775
3866
  while (true) {
3867
+ let db;
3868
+ let dbPromiseBeforeOp = null;
3776
3869
  try {
3777
- const db = await this._openDb();
3870
+ const openPromise = this._openDb();
3871
+ dbPromiseBeforeOp = this.dbPromise;
3872
+ db = await openPromise;
3778
3873
  return await op(db);
3779
3874
  }
3780
3875
  catch (e) {
3781
- if (numAttempts++ > _TRANSACTION_RETRY_COUNT) {
3782
- throw e;
3876
+ if (db) {
3877
+ db.close();
3878
+ if (dbPromiseBeforeOp && this.dbPromise === dbPromiseBeforeOp) {
3879
+ this.dbPromise = null;
3880
+ }
3783
3881
  }
3784
- if (this.dbPromise) {
3785
- const dbPromise = this.dbPromise;
3882
+ else if (this.dbPromise && this.dbPromise === dbPromiseBeforeOp) {
3883
+ const currentDbPromise = this.dbPromise;
3786
3884
  this.dbPromise = null;
3787
3885
  try {
3788
- const db = await dbPromise;
3789
- db.close();
3886
+ const openedDb = await currentDbPromise;
3887
+ openedDb.close();
3790
3888
  }
3791
3889
  catch { }
3792
3890
  }
3891
+ const isTimeout = e instanceof Error && e.message === DB_TIMEOUT_ERROR;
3892
+ if (isTimeout || numAttempts++ > _TRANSACTION_RETRY_COUNT) {
3893
+ throw e;
3894
+ }
3793
3895
  // TODO: consider adding exponential backoff
3794
3896
  }
3795
3897
  }
@@ -3869,17 +3971,21 @@ class IndexedDBLocalPersistence {
3869
3971
  }
3870
3972
  }
3871
3973
  async _isAvailable() {
3974
+ this._lastProbeTimedOut = false;
3872
3975
  try {
3873
3976
  if (!indexedDB) {
3874
3977
  return false;
3875
3978
  }
3876
3979
  await this._withRetries(async (db) => {
3877
- await _putObject(db, STORAGE_AVAILABLE_KEY, '1');
3878
- await _deleteObject(db, STORAGE_AVAILABLE_KEY);
3980
+ await _putObject(db, STORAGE_AVAILABLE_KEY, '1', _DB_PROBE_TIMEOUT_MS);
3981
+ await _deleteObject(db, STORAGE_AVAILABLE_KEY, _DB_PROBE_TIMEOUT_MS);
3879
3982
  });
3880
3983
  return true;
3881
3984
  }
3882
- catch { }
3985
+ catch (e) {
3986
+ this._lastProbeTimedOut =
3987
+ e instanceof Error && e.message === DB_TIMEOUT_ERROR;
3988
+ }
3883
3989
  return false;
3884
3990
  }
3885
3991
  async _withPendingWrite(write) {
@@ -3899,9 +4005,19 @@ class IndexedDBLocalPersistence {
3899
4005
  });
3900
4006
  }
3901
4007
  async _get(key) {
3902
- const obj = (await this._withRetries((db) => getObject(db, key)));
3903
- this.localCache[key] = obj;
3904
- return obj;
4008
+ try {
4009
+ const obj = (await this._withRetries((db) => getObject(db, key)));
4010
+ this.localCache[key] = obj;
4011
+ return obj;
4012
+ }
4013
+ catch (e) {
4014
+ if (e instanceof Error &&
4015
+ e.message === DB_TIMEOUT_ERROR &&
4016
+ this.localCache[key] != null) {
4017
+ return this.localCache[key];
4018
+ }
4019
+ throw e;
4020
+ }
3905
4021
  }
3906
4022
  async _remove(key) {
3907
4023
  return this._withPendingWrite(async () => {
@@ -3983,8 +4099,10 @@ class IndexedDBLocalPersistence {
3983
4099
  }
3984
4100
  if (!this.listeners[key]) {
3985
4101
  this.listeners[key] = new Set();
3986
- // Populate the cache to avoid spuriously triggering on first poll.
3987
- void this._get(key).catch(() => { }); // This can happen in the background async and we can return immediately.
4102
+ if (!(key in this.localCache)) {
4103
+ // Populate the cache to avoid spuriously triggering on first poll.
4104
+ void this._get(key).catch(() => { }); // This can happen in the background async and we can return immediately.
4105
+ }
3988
4106
  }
3989
4107
  this.listeners[key].add(listener);
3990
4108
  }