using GoodBooks.FrameworkBLL.Authentication; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; using FastEndpoints; namespace FrameworkSL.Endpoints.Authentication { /// /// Terminates the caller's session immediately. /// Removes the session row from MSESSIONSTORE so that the next API call /// from this LoginEventLogId receives 401 from SessionHeartbeatMiddleware. /// public class Logout : BaseEndpoint> { private readonly IAuthenticationBLL _authBLL; public Logout(IAuthenticationBLL authBLL) => _authBLL = authBLL; public override void Configure() { Delete("/Authentication/Logout"); AllowAnonymous(); } public record LogoutParameters( [property: FromHeader] string Login); protected override string? GetCacheKey(LogoutParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( LogoutParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _authBLL.LogoutAsync(login, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, CacheKeyLevel.NOT_REQUIRED, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500); } } } }