Skip to content

Commit

Permalink
[Auth] Detect if IndexedDB returns an empty array in platform_browser…
Browse files Browse the repository at this point in the history
…/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')`.
  • Loading branch information
DellaBitta authored Nov 29, 2023
1 parent 1d32137 commit 70e4cf6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-lobsters-own.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 8 additions & 5 deletions packages/auth/src/platform_browser/persistence/indexed_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 70e4cf6

Please sign in to comment.