From 6e5c03ce16c9b3c5ff666204896162c9a90e615b Mon Sep 17 00:00:00 2001 From: Wisley Alves Date: Mon, 11 Mar 2024 11:32:02 -0300 Subject: [PATCH] fix(auth): test time --- functions/lib/bling-auth/create-access.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/functions/lib/bling-auth/create-access.js b/functions/lib/bling-auth/create-access.js index ca820da..f3e1742 100644 --- a/functions/lib/bling-auth/create-access.js +++ b/functions/lib/bling-auth/create-access.js @@ -26,6 +26,7 @@ module.exports = function (clientId, clientSecret, code, storeId, tokenExpiratio .then(async (data) => { console.log('> Bling token => ', JSON.stringify(data)) if (documentRef) { + const gapTime = Timestamp.fromMillis((2 * 60 * 60 * 1000)) authenticate(data.access_token) const body = { ...data, @@ -33,9 +34,9 @@ module.exports = function (clientId, clientSecret, code, storeId, tokenExpiratio clientId, clientSecret, updatedAt: now, - expiredAt: Timestamp.fromMillis(now + (2 * 60 * 60 * 1000)) + expiredAt: now.toMillis() + gapTime } - console.log('>>> expiredAt: ', body.expiredAt.toDate(), ' ', now.toDate(), ' ') + console.log('>>> expiredAt: ', body.expiredAt.toDate(), ' ', now.toDate(), ' ', gapTime.toMillis()) if (code) { body.code = code } @@ -51,7 +52,7 @@ module.exports = function (clientId, clientSecret, code, storeId, tokenExpiratio .then((documentSnapshot) => { const expiredAt = documentSnapshot.get('expiredAt') if (documentSnapshot.exists && - now + tokenExpirationGap < expiredAt.toMillis() // token expires in 21600 s + now + Timestamp.fromMillis(tokenExpirationGap) < expiredAt.toMillis() // token expires in 21600 s ) { authenticate(documentSnapshot.get('access_token')) } else {