Skip to content

[Auth] Fix issue with indexeddb retry logic #4146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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