diff --git a/packages/plugins/@nocobase/plugin-auth/src/server/token-controller.ts b/packages/plugins/@nocobase/plugin-auth/src/server/token-controller.ts index ba57cde6733..7b7c3ed57c6 100644 --- a/packages/plugins/@nocobase/plugin-auth/src/server/token-controller.ts +++ b/packages/plugins/@nocobase/plugin-auth/src/server/token-controller.ts @@ -84,6 +84,14 @@ export class TokenController implements TokenControlService { }); } + private async cleanupSessionExpiredTokens(userId: number) { + try { + await this.removeSessionExpiredTokens(userId); + } catch (err) { + this.logger.error(err, { module: 'auth', submodule: 'token-controller', method: 'removeSessionExpiredTokens' }); + } + } + async add({ userId, authenticator }: { userId: number; authenticator?: string }) { const jti = randomUUID(); const currTS = Date.now(); @@ -97,15 +105,11 @@ export class TokenController implements TokenControlService { }; await this.setTokenInfo(jti, data); - try { - if (process.env.DB_DIALECT === 'sqlite') { - // SQLITE does not support concurrent operations - await this.removeSessionExpiredTokens(userId); - } else { - this.removeSessionExpiredTokens(userId); - } - } catch (err) { - this.logger.error(err, { module: 'auth', submodule: 'token-controller', method: 'removeSessionExpiredTokens' }); + if (process.env.DB_DIALECT === 'sqlite') { + // SQLITE does not support concurrent operations + await this.cleanupSessionExpiredTokens(userId); + } else { + this.cleanupSessionExpiredTokens(userId); } return data;