Skip to content

Commit

Permalink
fix(auth): test time
Browse files Browse the repository at this point in the history
  • Loading branch information
wisley7l committed Mar 11, 2024
1 parent e593754 commit c235236
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions functions/lib/bling-auth/create-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ 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,
storeId,
clientId,
clientSecret,
updatedAt: now,
expiredAt: now.toMillis() + gapTime.toMillis()
expiredAt: Timestamp.fromMillis(now.toMillis() + (2 * 60 * 60 * 1000))
}
console.log('>>> expiredAt: ', body.expiredAt.toDate(), ' ', now.toDate(), ' ', gapTime.toMillis())
console.log('>>> expiredAt: ', body.expiredAt.toDate(), ' ', now.toDate(), ' ')
if (code) {
body.code = code
}
Expand All @@ -52,7 +51,7 @@ module.exports = function (clientId, clientSecret, code, storeId, tokenExpiratio
.then((documentSnapshot) => {
const expiredAt = documentSnapshot.get('expiredAt')
if (documentSnapshot.exists &&
now + Timestamp.fromMillis(tokenExpirationGap) < expiredAt.toMillis() // token expires in 21600 s
Timestamp.fromMillis(now.toMillis() + tokenExpirationGap) < expiredAt.toMillis() // token expires in 21600 s
) {
authenticate(documentSnapshot.get('access_token'))
} else {
Expand Down

0 comments on commit c235236

Please sign in to comment.