Skip to content

Commit ccf3616

Browse files
committed
Protect against missing non-existent snapshot
1 parent eaecf9c commit ccf3616

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

database/helpers/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export const snapshotToData = (
77
snapshot: database.DataSnapshot,
88
keyField?: string
99
) => {
10+
if (!snapshot.exists) {
11+
return null;
12+
}
13+
1014
const val = snapshot.val();
1115
if (isObject(val)) {
1216
return {

firestore/helpers/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ export const snapshotToData = (
44
snapshot: firestore.DocumentSnapshot,
55
idField?: string
66
) => {
7-
if (!snapshot.exists) return null;
7+
if (!snapshot.exists) {
8+
return null;
9+
}
10+
811
return {
912
...snapshot.data(),
1013
...(idField ? { [idField]: snapshot.id } : null),

0 commit comments

Comments
 (0)