Reviewed-on: #2881 Reviewed-by: Javier Segarra <jsegarra@verdnatura.es>
This commit is contained in:
commit
1fac261682
|
@ -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]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue