diff --git a/packages/auth/src/Domain/Authenticator/AuthenticatorRepositoryInterface.ts b/packages/auth/src/Domain/Authenticator/AuthenticatorRepositoryInterface.ts index 123788e21..e5d5477d6 100644 --- a/packages/auth/src/Domain/Authenticator/AuthenticatorRepositoryInterface.ts +++ b/packages/auth/src/Domain/Authenticator/AuthenticatorRepositoryInterface.ts @@ -7,6 +7,7 @@ export interface AuthenticatorRepositoryInterface { findById(id: UniqueEntityId): Promise findByUserUuidAndCredentialId(userUuid: Uuid, credentialId: string): Promise save(authenticator: Authenticator): Promise + updateCounter(id: UniqueEntityId, counter: number): Promise remove(authenticator: Authenticator): Promise removeByUserUuid(userUuid: Uuid): Promise } diff --git a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.spec.ts b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.spec.ts index 34d4cb849..42ef36afa 100644 --- a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.spec.ts +++ b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.spec.ts @@ -36,7 +36,7 @@ describe('VerifyAuthenticatorAuthenticationResponse', () => { authenticatorRepository = {} as jest.Mocked authenticatorRepository.findByUserUuidAndCredentialId = jest.fn().mockReturnValue(authenticator) - authenticatorRepository.save = jest.fn() + authenticatorRepository.updateCounter = jest.fn() authenticatorChallengeRepository = {} as jest.Mocked authenticatorChallengeRepository.findByUserUuid = jest.fn().mockReturnValue({ @@ -221,6 +221,6 @@ describe('VerifyAuthenticatorAuthenticationResponse', () => { }) expect(result.isFailed()).toBeFalsy() - expect(authenticatorRepository.save).toHaveBeenCalled() + expect(authenticatorRepository.updateCounter).toHaveBeenCalled() }) }) diff --git a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.ts b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.ts index 2720dcaee..901bbbdf7 100644 --- a/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.ts +++ b/packages/auth/src/Domain/UseCase/VerifyAuthenticatorAuthenticationResponse/VerifyAuthenticatorAuthenticationResponse.ts @@ -60,9 +60,7 @@ export class VerifyAuthenticatorAuthenticationResponse implements UseCaseInterfa return Result.fail(`Could not verify authenticator authentication response: ${(error as Error).message}`) } - authenticator.props.counter = verification.authenticationInfo.newCounter as number - - await this.authenticatorRepository.save(authenticator) + await this.authenticatorRepository.updateCounter(authenticator.id, verification.authenticationInfo.newCounter) return Result.ok(true) } diff --git a/packages/auth/src/Infra/MySQL/MySQLAuthenticatorRepository.ts b/packages/auth/src/Infra/MySQL/MySQLAuthenticatorRepository.ts index 36881ced1..eb58a7a3a 100644 --- a/packages/auth/src/Infra/MySQL/MySQLAuthenticatorRepository.ts +++ b/packages/auth/src/Infra/MySQL/MySQLAuthenticatorRepository.ts @@ -11,6 +11,19 @@ export class MySQLAuthenticatorRepository implements AuthenticatorRepositoryInte private mapper: MapperInterface, ) {} + async updateCounter(id: UniqueEntityId, counter: number): Promise { + await this.ormRepository + .createQueryBuilder() + .update() + .set({ + counter, + }) + .where('uuid = :uuid', { + uuid: id.toString(), + }) + .execute() + } + async removeByUserUuid(userUuid: Uuid): Promise { await this.ormRepository .createQueryBuilder()