From ba48d93c1e97cd94f8ef2e5a60f1e9dc8bd89c88 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 20 Jun 2024 23:28:11 +0200 Subject: [PATCH] perf(salix): refs #6264 #6264 remove save token as debug row --- back/methods/vn-user/renew-token.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/back/methods/vn-user/renew-token.js b/back/methods/vn-user/renew-token.js index ae554d398..ae2d36e3e 100644 --- a/back/methods/vn-user/renew-token.js +++ b/back/methods/vn-user/renew-token.js @@ -16,44 +16,44 @@ module.exports = Self => { accessScopes: ['DEFAULT', 'read:multimedia']}); Self.renewToken = async function(ctx) { - let accessToken; - let token; + let createTokenOptions = {}; + let token; let isNotExceeded; try { token = ctx.req.accessToken; + const {courtesyTime} = await models.AccessTokenConfig.findOne({ fields: ['courtesyTime'] }); - const isNotExceeded = await Self.validateToken(ctx); + isNotExceeded = await Self.validateToken(ctx); if (isNotExceeded) return token; // Schedule to remove current token setTimeout(async() => { + let exists; try { - const exists = await models.AccessToken.findById(token.id); + exists = await models.AccessToken.findById(token.id); exists && await Self.logout(token.id); } catch (error) { // eslint-disable-next-line no-console console.error(error); - const body = JSON.stringify({err: error, token}); + const body = {error: error.message, now: Date.now(), userId: token?.userId ?? null, exists}; await handleError(body); throw new Error(error); } }, courtesyTime * 1000); // Get scopes - - let createTokenOptions = {}; const {scopes} = token; if (scopes) createTokenOptions = {scopes: [scopes[0]]}; // Create new accessToken const user = await Self.findById(token.userId); - accessToken = await user.accessTokens.create(createTokenOptions); + const accessToken = await user.accessTokens.create(createTokenOptions); return {id: accessToken.id, ttl: accessToken.ttl}; } catch (error) { - const body = JSON.stringify({error: error.message, token, accessToken}); + const body = {error: error.message, now: Date.now(), userId: token?.userId ?? null, createTokenOptions, isNotExceeded}; await handleError(body); throw new Error(error); } @@ -61,5 +61,6 @@ module.exports = Self => { }; async function handleError(body, tag = 'renewToken') { + body = JSON.stringify(body); await models.Application.rawSql('CALL util.debugAdd(?,?);', [tag, body]); }