From b6c0ff01bf2767fb869ea48817365fed0f82d57c Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 26 Aug 2024 12:04:03 +0200 Subject: [PATCH] fix: refs #7811 Renew token crash --- back/methods/vn-user/renew-token.js | 30 +++++++++++++---------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/back/methods/vn-user/renew-token.js b/back/methods/vn-user/renew-token.js index ae2d36e3e..688e9a770 100644 --- a/back/methods/vn-user/renew-token.js +++ b/back/methods/vn-user/renew-token.js @@ -29,18 +29,8 @@ module.exports = Self => { return token; // Schedule to remove current token - setTimeout(async() => { - let exists; - try { - 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 = {error: error.message, now: Date.now(), userId: token?.userId ?? null, exists}; - await handleError(body); - throw new Error(error); - } + setTimeout(() => { + Self.logout(token.id); }, courtesyTime * 1000); // Get scopes @@ -53,14 +43,20 @@ module.exports = Self => { return {id: accessToken.id, ttl: accessToken.ttl}; } catch (error) { - const body = {error: error.message, now: Date.now(), userId: token?.userId ?? null, createTokenOptions, isNotExceeded}; - await handleError(body); + const body = { + error: error.message, + userId: token?.userId ?? null, + token: token?.id, + scopes: token?.scopes, + createTokenOptions, + isNotExceeded + }; + await handleError(JSON.stringify(body)); throw new Error(error); } }; }; -async function handleError(body, tag = 'renewToken') { - body = JSON.stringify(body); - await models.Application.rawSql('CALL util.debugAdd(?,?);', [tag, body]); +async function handleError(body) { + await models.Application.rawSql('CALL util.debugAdd(?,?);', ['renewToken', body]); } -- 2.40.1