Refresh.cs 809 B

1234567891011121314151617181920212223242526272829303132
  1. using MediatR;
  2. using Web.Api.Extensions;
  3. using Web.Api.Common;
  4. namespace Web.Api.Endpoints.Auth;
  5. internal sealed class Refresh : IEndpoint
  6. {
  7. public sealed record Request(string RefreshToken);
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapPost("api/auth/refresh", async (
  11. Request request,
  12. ISender sender,
  13. CancellationToken ct
  14. ) => {
  15. var command = new Application.Features.Api.Auth.RefreshToken.Command(
  16. request.RefreshToken
  17. );
  18. var result = await sender.Send(command, ct);
  19. return result.Match(
  20. data => ApiResponse.Ok(data),
  21. CustomResults.Problem
  22. );
  23. })
  24. .WithTags("Auth")
  25. .AllowAnonymous();
  26. }
  27. }