fix: refs #7811 Renew token crash #2881

Merged
guillermo merged 1 commits from 7811-renewTokenFix into master 2024-08-26 10:12:05 +00:00
1 changed files with 13 additions and 17 deletions

View File

@ -29,18 +29,8 @@ module.exports = Self => {
return token; return token;
// Schedule to remove current token // Schedule to remove current token
setTimeout(async() => { setTimeout(() => {
let exists; Self.logout(token.id);
try {
exists = await models.AccessToken.findById(token.id);
Review

Como aclaración, no hace falta hacer esta comprobación, ya que ya se realiza dentro de logout

Como aclaración, no hace falta hacer esta comprobación, ya que ya se realiza dentro de logout
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);
}
}, courtesyTime * 1000); }, courtesyTime * 1000);
// Get scopes // Get scopes
@ -53,14 +43,20 @@ module.exports = Self => {
return {id: accessToken.id, ttl: accessToken.ttl}; return {id: accessToken.id, ttl: accessToken.ttl};
} catch (error) { } catch (error) {
const body = {error: error.message, now: Date.now(), userId: token?.userId ?? null, createTokenOptions, isNotExceeded}; const body = {
await handleError(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); throw new Error(error);
} }
}; };
}; };
async function handleError(body, tag = 'renewToken') { async function handleError(body) {
body = JSON.stringify(body); await models.Application.rawSql('CALL util.debugAdd(?,?);', ['renewToken', body]);
await models.Application.rawSql('CALL util.debugAdd(?,?);', [tag, body]);
} }