refs #5554 fix: eliminada transacción en el back 'renewToken'
This commit is contained in:
parent
eab329b230
commit
834a3aa959
|
@ -8,25 +8,15 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.renewToken = async function(ctx, options) {
|
||||
Self.renewToken = async function(ctx) {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const created = ctx.req.accessToken.created;
|
||||
// const tokenId = ctx.req.accessToken.id;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const differenceMilliseconds = now - created;
|
||||
const differenceSeconds = Math.floor(differenceMilliseconds / 1000); // Convertir la diferencia a segundos
|
||||
const differenceSeconds = Math.floor(differenceMilliseconds / 1000);
|
||||
|
||||
const accessTokenConfig = await models.AccessTokenConfig.findOne();
|
||||
if (differenceSeconds <= accessTokenConfig.renewPeriod) {
|
||||
|
@ -39,9 +29,10 @@ module.exports = Self => {
|
|||
return response;
|
||||
}
|
||||
|
||||
const accessToken = await models.AccessToken.create({userId: userId}, myOptions);
|
||||
await models.AccessToken.destroyAll({userId: userId}, myOptions);
|
||||
// await models.AccessToken.destroyById(tokenId, myOptions);
|
||||
await models.AccessToken.destroyAll({userId: userId});
|
||||
// await models.AccessToken.destroyById(tokenId);
|
||||
|
||||
const accessToken = await models.AccessToken.create({userId: userId});
|
||||
|
||||
return {token: accessToken.id, created: accessToken.created};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue