From e5c6641fdeb050ad444ab6d73b6449172ffc511c Mon Sep 17 00:00:00 2001 From: igorsfreitas Date: Fri, 14 Feb 2020 15:11:46 -0300 Subject: [PATCH] fix(firestore): fix handling update tokens and get auth with firestore/cloud functions (#6) * fix(update-tokens): fix handleRefreshToken to run after promise * fix(update-tokens): setTimeout only works out of serveless * fix(get-auth): fix store_id object source --- lib/methods/get-auth.js | 2 +- lib/services/update-tokens.js | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/methods/get-auth.js b/lib/methods/get-auth.js index 88e1e9a..84fad7d 100644 --- a/lib/methods/get-auth.js +++ b/lib/methods/get-auth.js @@ -51,7 +51,7 @@ const getAuth = ({ dbFilename, db, table }) => { } query.get() .then(row => { - if (row.empty || (row.store_id !== storeId)) { + if (row.empty || (row.docs[0].data().store_id !== storeId)) { handleRejectPromise(reject) } else { handleResolvePromise(resolve, row.docs[0].data()) diff --git a/lib/services/update-tokens.js b/lib/services/update-tokens.js index b037fd7..542c2a0 100644 --- a/lib/services/update-tokens.js +++ b/lib/services/update-tokens.js @@ -43,18 +43,20 @@ const updateTokens = (client) => { values.map(item => { rows = rows.concat(item.docs) }) + if (rows && rows.length > 0) { + rows.map(row => { + handleRefreshToken(row.data()) + }) + } }) - if (rows && rows.length > 0) { - rows.map(row => { - handleRefreshToken(row.data()) - }) - } } } - // run task with 1 hour interval - const hour = 60 * 60 * 1000 - setInterval(task, hour) + // if database engine is sqlite, run task with 1 hour interval + if (dbFilename) { + const hour = 60 * 60 * 1000 + setInterval(task, hour) + } task() }