fix(core.gbapp): #387 adding /setupSecurity multiple tokens. Refresh token fix. @othonlima @christopherdecastilho.

This commit is contained in:
Rodrigo Rodriguez 2023-12-28 07:56:55 -03:00
parent 4bd2340613
commit 84858db975

View file

@ -611,8 +611,12 @@ export class GBVMService extends GBService {
// Auto update Bearar authentication for the first token. // Auto update Bearar authentication for the first token.
const expiresOn = new Date(global[tokenName + "_expiresOn"]); 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}); const {token, expiresOn} = await sys.getCustomToken({pid, tokenName});
global[tokenName] = token; global[tokenName] = token;