Login.cs 835 B

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