Here I log in with a username but I want to log in with email. if I type email instead of username I return an error
public async Task<IActionResult> Login([FromBody] LoginModel model) { var user = await userManager.FindByNameAsync(model.Username);
if (user != null && await userManager.CheckPasswordAsync(user, model.Password)) { var userRoles = await userManager.GetRolesAsync(user);
var authClaims = new List<Claim> { new Claim(ClaimTypes.Name, user.UserName), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), };
foreach (var userRole in userRoles) { authClaims.Add(new Claim(ClaimTypes.Role, userRole)); }
var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JWT:Secret"]));
var token = new JwtSecurityToken( issuer: _configuration["JWT:ValidIssuer"], audience: _configuration["JWT:ValidAudience"], expires: DateTime.Now.AddDays(30), claims: authClaims, signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256) ); return Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token), expiration = token.ValidTo, PhoneNumber=model.Username, Id=user.Id
}); } return Unauthorized(); }