Skip to content

Commit

Permalink
fix(get-auth): prevent needing to add firestore composite index
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Apr 21, 2020
1 parent 3a6973b commit 966c3f2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/methods/get-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const getAuth = ({ collRef, db, table }) => {
docOrQueryRef = collRef.doc(authenticationId)
} else {
docOrQueryRef = collRef.where('store_id', '==', storeId)
.orderBy('updated_at', 'desc').limit(1)
}

// run document get or query
Expand All @@ -61,7 +60,13 @@ const getAuth = ({ collRef, db, table }) => {
} else if (docOrQuerySnapshot.size > 0) {
// is querySnapshot
docOrQuerySnapshot.forEach(documentSnapshot => {
data = documentSnapshot.data()
const doc = documentSnapshot.data()
if (
!data || !data.updated_at ||
(doc.updated_at && doc.updated_at.seconds >= data.updated_at.seconds)
) {
data = doc
}
})
}
if (data) {
Expand Down

0 comments on commit 966c3f2

Please sign in to comment.