feat(app): implement LogoutCommand handler with idempotent revocation

This commit is contained in:
2026-04-14 13:28:10 -03:00
parent 15a7687e4c
commit 6c02197369
3 changed files with 28 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
namespace SIGCM2.Application.Auth.Logout;
public sealed record LogoutCommand(int UsuarioId);

View File

@@ -0,0 +1,22 @@
using SIGCM2.Application.Abstractions;
using SIGCM2.Application.Abstractions.Persistence;
namespace SIGCM2.Application.Auth.Logout;
public sealed class LogoutCommandHandler : ICommandHandler<LogoutCommand, LogoutResponseDto>
{
private readonly IRefreshTokenRepository _refreshRepo;
public LogoutCommandHandler(IRefreshTokenRepository refreshRepo)
{
_refreshRepo = refreshRepo;
}
public async Task<LogoutResponseDto> Handle(LogoutCommand command)
{
// Revoke all active tokens for the user across all families.
// Idempotent: 0 rows affected is not an error.
await _refreshRepo.RevokeAllActiveForUserAsync(command.UsuarioId, DateTime.UtcNow);
return new LogoutResponseDto(true, "Sesión cerrada correctamente");
}
}

View File

@@ -0,0 +1,3 @@
namespace SIGCM2.Application.Auth.Logout;
public sealed record LogoutResponseDto(bool Success, string Mensaje);