()
| 198 | } |
| 199 | |
| 200 | private int GetUserId() |
| 201 | { |
| 202 | var claims = User.Claims.Select(c => $"{c.Type}: {c.Value}"); |
| 203 | Console.WriteLine($"[UsersController] User Claims: {string.Join(", ", claims)}"); |
| 204 | |
| 205 | var idClaim = User.FindFirst(ClaimTypes.NameIdentifier)?.Value |
| 206 | ?? User.FindFirst("sub")?.Value |
| 207 | ?? User.FindFirst("id")?.Value |
| 208 | ?? User.FindFirst(JwtRegisteredClaimNames.Sub)?.Value; |
| 209 | |
| 210 | if (int.TryParse(idClaim, out int userId)) |
| 211 | { |
| 212 | Console.WriteLine($"[UsersController] Extracted UserId: {userId}"); |
| 213 | return userId; |
| 214 | } |
| 215 | |
| 216 | Console.WriteLine("[UsersController] WARNING: UserId claim not found or not an integer."); |
| 217 | return 0; |
| 218 | } |
| 219 | } |
nothing calls this directly
no outgoing calls
no test coverage detected