Rest Api. JWT auth. How to make api stateless?
Here are endpoints I have public static void RegisterTodoListEndpoints(this IEndpointRouteBuilder app) { var group = app.MapGroup("api/lists").RequireAuthorization(); /// <summary> /// Returns lists of current user (Id, Title, Ammount of tasks) /// </summary> group.MapGet("", GetAllTodos); /// <summary> /// Create new todo list /// </summary> group.MapPost("", CreateTodoList); /// <summary> /// Return list and its tasks. 403 if user is not owner of list /// </summary> group.MapGet("/{listId}", GetTodoListById); /// <summary> /// Deletes list and its tasks. 403 if user is not owner of list /// </summary> group.MapDelete("{listId}", DeleteTodoList); /// <summary> /// Creates new task. 403 if user is not owner of list /// </summary> group.MapPost("/{listId}/tasks", CreateTodoTask); /// <summary> /// Updates new task. 403 if user is not owner of list /// </summary> group.MapPatch("{listId}/tasks/{taskId}", UpdateTodoTask); } Lets take a look at GetTodoListById. Using ClaimsPrincipal makes it not stateless? private static async Task<IResult> GetTodoListById( ISender sender, ClaimsPrincipal claimsPrincipal, [FromRoute] int listId) { var userId = int.Parse(claimsPrincipal.FindFirstValue(ClaimTypes.NameIdentifier)!); var query = new GetTodoListByIdQuery(listId, userId); var response = await sender.Send(query); if (response.IsFailure) { return response.AsTypedErrorResult(); } return TypedResults.Ok(response.Value); }