| 1234567891011121314151617181920212223242526272829303132333435 |
- using System.Security.Claims;
- using MediatR;
- using Web.Api.Extensions;
- using Web.Api.Common;
- namespace Web.Api.Endpoints.Auth;
- internal sealed class Profile : IEndpoint
- {
- public void MapEndpoint(IEndpointRouteBuilder app)
- {
- app.MapGet("api/auth/profile", async (
- ClaimsPrincipal user,
- ISender sender,
- CancellationToken ct
- ) => {
- var memberID = user.GetMemberID();
- if (memberID is null)
- {
- return ApiResponse.Fail(StatusCodes.Status401Unauthorized, "Invalid token");
- }
- var query = new Application.Features.Api.Auth.GetProfile.Query(memberID.Value);
- var result = await sender.Send(query, ct);
- return result.Match(
- data => ApiResponse.Ok(data),
- CustomResults.Problem
- );
- })
- .WithTags("Auth")
- .RequireAuthorization();
- }
- }
|