I have a problem when reading the data saved in JWT, it is returning everything as a string, the correct thing would be to ensure that the returned values are in the correct typing, for example the firstAccess field saves a boolean true or false but is returning a string “true” or “false”, I believe that this is not a good practice. How can I ensure that it returns the correct typing?
JWT:
{
"id": 1,
"first_access": false,
"nbf": 1722250357,
"exp": 1722279157,
"iat": 1722250357
}
C#:
string token = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ",
"");
var jwtToken = new JwtSecurityTokenHandler().ReadToken(token) as JwtSecurityToken;
var firstAccess = jwtToken.Claims.FirstOrDefault(c => c.Type == "first_access")?.Value;
if (firstAccess == "false")
return BadRequest(new { message = ErrorMessages.ChangePasswordDenied });