diff --git a/lib/methods/get-auth.js b/lib/methods/get-auth.js index 9d7da8c..dd4be51 100644 --- a/lib/methods/get-auth.js +++ b/lib/methods/get-auth.js @@ -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 @@ -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) {