diff --git a/.changeset/tiny-lobsters-own.md b/.changeset/tiny-lobsters-own.md new file mode 100644 index 00000000000..88c32d2cf9e --- /dev/null +++ b/.changeset/tiny-lobsters-own.md @@ -0,0 +1,5 @@ +--- +'@firebase/auth': patch +--- + +Protection from enumerating an empty list in Auth's reading of IndexedDB results, as this causes errors in some macOS and iOS browser runtimes. diff --git a/packages/auth/src/platform_browser/persistence/indexed_db.ts b/packages/auth/src/platform_browser/persistence/indexed_db.ts index a9231c0870d..597b45d3ff4 100644 --- a/packages/auth/src/platform_browser/persistence/indexed_db.ts +++ b/packages/auth/src/platform_browser/persistence/indexed_db.ts @@ -369,13 +369,16 @@ class IndexedDBLocalPersistence implements InternalPersistence { const keys = []; const keysInResult = new Set(); - for (const { fbase_key: key, value } of result) { - keysInResult.add(key); - if (JSON.stringify(this.localCache[key]) !== JSON.stringify(value)) { - this.notifyListeners(key, value as PersistenceValue); - keys.push(key); + if (result.length !== 0) { + for (const { fbase_key: key, value } of result) { + keysInResult.add(key); + if (JSON.stringify(this.localCache[key]) !== JSON.stringify(value)) { + this.notifyListeners(key, value as PersistenceValue); + keys.push(key); + } } } + for (const localKey of Object.keys(this.localCache)) { if (this.localCache[localKey] && !keysInResult.has(localKey)) { // Deleted