Skip to content

Commit

Permalink
[Auth] Fix issue with indexeddb retry logic (#4146)
Browse files Browse the repository at this point in the history
* Fix issue with indexeddb retry logic

* Add changeset

* Fix broken changest
  • Loading branch information
sam-gc committed Dec 2, 2020
1 parent 1849b0d commit 11563b2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/wet-dolphins-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@firebase/auth": patch
"firebase": patch
---

Fix issue with IndexedDB retry logic causing uncaught errors
6 changes: 6 additions & 0 deletions packages/auth/src/storage/indexeddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
};
Expand Down
27 changes: 27 additions & 0 deletions packages/auth/test/storage/indexeddb_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 11563b2

Please sign in to comment.