Skip to content

Commit 297de75

Browse files
authored
Merge 2530280 into 772c4d1
2 parents 772c4d1 + 2530280 commit 297de75

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

.changeset/wet-dolphins-play.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@firebase/auth": patch
3+
"firebase": patch
4+
---
5+
6+
Fix issue with IndexedDB retry logic causing uncaught errors

packages/auth/src/storage/indexeddb.js

+6
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,12 @@ fireauth.storage.IndexedDB.prototype.withRetry_ = function(transaction) {
374374
db.close();
375375
this.initPromise_ = undefined;
376376
return attempt(resolve, reject);
377+
}).thenCatch((error) => {
378+
// Make sure any errors caused by initializeDbAndRun_() or
379+
// db.close() are caught as well and trigger a rejection. If at
380+
// this point, we are probably in a private browsing context or
381+
// environment that does not support indexedDB.
382+
reject(error);
377383
});
378384
});
379385
};

packages/auth/test/storage/indexeddb_test.js

+27
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,33 @@ function testIndexedDb_setGetRemove_connectionClosed() {
413413
}
414414

415415

416+
function testIndexedDb_failingOnDbOpen() {
417+
manager = getDefaultFireauthManager();
418+
manager.addStorageListener(() => {
419+
fail('Storage should not be triggered for local changes!');
420+
});
421+
let errorThrown = false;
422+
indexedDBMock.open = () => {
423+
throw new Error('InvalidStateError: A mutation operation was attempted ' +
424+
'on a database that did not allow mutations.');
425+
};
426+
return goog.Promise.resolve()
427+
.then(() => {
428+
return manager.get('key1');
429+
})
430+
.thenCatch((error) => {
431+
assertEquals(
432+
error.message,
433+
'InvalidStateError: A mutation operation was attempted on a ' +
434+
'database that did not allow mutations.');
435+
errorThrown = true;
436+
})
437+
.then(() => {
438+
assertTrue(errorThrown);
439+
});
440+
}
441+
442+
416443
function testStartListeners() {
417444
manager = getDefaultFireauthManager();
418445
var listener1 = goog.testing.recordFunction();

0 commit comments

Comments
 (0)