feat(app): implement LogoutCommand handler with idempotent revocation
This commit is contained in:
3
src/api/SIGCM2.Application/Auth/Logout/LogoutCommand.cs
Normal file
3
src/api/SIGCM2.Application/Auth/Logout/LogoutCommand.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace SIGCM2.Application.Auth.Logout;
|
||||
|
||||
public sealed record LogoutCommand(int UsuarioId);
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace SIGCM2.Application.Auth.Logout;
|
||||
|
||||
public sealed record LogoutResponseDto(bool Success, string Mensaje);
|
||||
Reference in New Issue
Block a user