diff --git a/.changeset/wet-dolphins-play.md b/.changeset/wet-dolphins-play.md new file mode 100644 index 00000000000..e9a93deaafc --- /dev/null +++ b/.changeset/wet-dolphins-play.md @@ -0,0 +1,6 @@ +--- +"@firebase/auth": patch +"firebase": patch +--- + +Fix issue with IndexedDB retry logic causing uncaught errors diff --git a/packages/auth/src/storage/indexeddb.js b/packages/auth/src/storage/indexeddb.js index 002e5fd6c89..9633a9a139f 100644 --- a/packages/auth/src/storage/indexeddb.js +++ b/packages/auth/src/storage/indexeddb.js @@ -374,6 +374,12 @@ fireauth.storage.IndexedDB.prototype.withRetry_ = function(transaction) { db.close(); this.initPromise_ = undefined; return attempt(resolve, reject); + }).thenCatch((error) => { + // Make sure any errors caused by initializeDbAndRun_() or + // db.close() are caught as well and trigger a rejection. If at + // this point, we are probably in a private browsing context or + // environment that does not support indexedDB. + reject(error); }); }); }; diff --git a/packages/auth/test/storage/indexeddb_test.js b/packages/auth/test/storage/indexeddb_test.js index d7b217be0ad..08591f9da04 100644 --- a/packages/auth/test/storage/indexeddb_test.js +++ b/packages/auth/test/storage/indexeddb_test.js @@ -413,6 +413,33 @@ function testIndexedDb_setGetRemove_connectionClosed() { } +function testIndexedDb_failingOnDbOpen() { + manager = getDefaultFireauthManager(); + manager.addStorageListener(() => { + fail('Storage should not be triggered for local changes!'); + }); + let errorThrown = false; + indexedDBMock.open = () => { + throw new Error('InvalidStateError: A mutation operation was attempted ' + + 'on a database that did not allow mutations.'); + }; + return goog.Promise.resolve() + .then(() => { + return manager.get('key1'); + }) + .thenCatch((error) => { + assertEquals( + error.message, + 'InvalidStateError: A mutation operation was attempted on a ' + + 'database that did not allow mutations.'); + errorThrown = true; + }) + .then(() => { + assertTrue(errorThrown); + }); +} + + function testStartListeners() { manager = getDefaultFireauthManager(); var listener1 = goog.testing.recordFunction();