Skip to content

Commit 70e4cf6

Browse files
authored
[Auth] Detect if IndexedDB returns an empty array in platform_browser/persistence. (#7825)
Protection from enumerating an empty list in Auth's reading of IndexedDB results, as this causes errors in some macOS and iOS browser runtimes. This change addresses Issue #7737 which reported an error of `TypeError undefined is not an object (evaluating 'o.fbase_key')`.
1 parent 1d32137 commit 70e4cf6

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

.changeset/tiny-lobsters-own.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/auth': patch
3+
---
4+
5+
Protection from enumerating an empty list in Auth's reading of IndexedDB results, as this causes errors in some macOS and iOS browser runtimes.

packages/auth/src/platform_browser/persistence/indexed_db.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,16 @@ class IndexedDBLocalPersistence implements InternalPersistence {
369369

370370
const keys = [];
371371
const keysInResult = new Set();
372-
for (const { fbase_key: key, value } of result) {
373-
keysInResult.add(key);
374-
if (JSON.stringify(this.localCache[key]) !== JSON.stringify(value)) {
375-
this.notifyListeners(key, value as PersistenceValue);
376-
keys.push(key);
372+
if (result.length !== 0) {
373+
for (const { fbase_key: key, value } of result) {
374+
keysInResult.add(key);
375+
if (JSON.stringify(this.localCache[key]) !== JSON.stringify(value)) {
376+
this.notifyListeners(key, value as PersistenceValue);
377+
keys.push(key);
378+
}
377379
}
378380
}
381+
379382
for (const localKey of Object.keys(this.localCache)) {
380383
if (this.localCache[localKey] && !keysInResult.has(localKey)) {
381384
// Deleted

0 commit comments

Comments
 (0)