File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
exercise.wwwapi/Endpoints Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments