From 84858db9756bd0599e517791a0bd4feb2ac14f0a Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Thu, 28 Dec 2023 07:56:55 -0300 Subject: [PATCH] fix(core.gbapp): #387 adding /setupSecurity multiple tokens. Refresh token fix. @othonlima @christopherdecastilho. --- packages/basic.gblib/services/GBVMService.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/basic.gblib/services/GBVMService.ts b/packages/basic.gblib/services/GBVMService.ts index a823daeb..da40d4e3 100644 --- a/packages/basic.gblib/services/GBVMService.ts +++ b/packages/basic.gblib/services/GBVMService.ts @@ -611,8 +611,12 @@ export class GBVMService extends GBService { // Auto update Bearar authentication for the first token. const expiresOn = new Date(global[tokenName + "_expiresOn"]); - if (expiresOn.getTime() < new Date().getTime() || firstTime) { - + const expiration = expiresOn.getTime() - (10 * 60 * 1000); + + // Expires token 10min. before or if it the first time, load it. + + if (expiration < new Date().getTime() || firstTime) { + console.log ('Expired. Refreshing token...'); const {token, expiresOn} = await sys.getCustomToken({pid, tokenName}); global[tokenName] = token;