Skip to content

Commit ee233e2

Browse files
Update UserEndpoints.cs
1 parent 201c299 commit ee233e2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

exercise.wwwapi/Endpoints/UserEndpoints.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public static void ConfigureAuthApi(this WebApplication app)
3535
/// <param name="repository">
3636
/// The user repository used to fetch users.
3737
/// </param>
38+
/// <param name="claims">
39+
/// <see cref="ClaimsPrincipal"/>-user that authorizes the user to use this endpoint.
40+
/// </param>
3841
/// <param name="name">
3942
/// Optional search term to filter users by first name, last name, or "FirstName LastName".
4043
/// </param>
@@ -45,8 +48,15 @@ public static void ConfigureAuthApi(this WebApplication app)
4548
[Authorize]
4649
[ProducesResponseType(StatusCodes.Status200OK)]
4750
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
48-
private static async Task<IResult> GetUsers(IRepository<User> repository, string? name)
51+
private static async Task<IResult> GetUsers(IRepository<User> repository, ClaimsPrincipal claims, string? name)
4952
{
53+
int? id = claims.UserRealId();
54+
if (id == null)
55+
{
56+
return TypedResults.Ok(new ResponseDTO<object>()
57+
{ Message = "Invalid token" });
58+
}
59+
5060
IEnumerable<User> results = await repository.Get();
5161
string? search = name?.Trim().ToLower();
5262

0 commit comments

Comments
 (0)