23 lines
787 B
C#
23 lines
787 B
C#
|
|
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");
|
||
|
|
}
|
||
|
|
}
|