fix: refs #7811 Renew token crash
gitea/salix/pipeline/pr-master This commit looks good Details

This commit is contained in:
Guillermo Bonet 2024-08-26 12:04:03 +02:00
parent 5b964aec1e
commit b6c0ff01bf
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);
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]);
} }