Unable to Login with the user name for the login page instead of user Email

in one of our tenant we are using custom database in Authentication for our application in that for login page we have written the code for the to login using email or username. when the user uses the email for the login its working fine but when the same user try to go through his user name its showing that invalid email,user,password.

we are using the below query. we are using tedious library in my code

console.log(email,“Email”);
const query = ‘SELECT Id, UserName, Email, PasswordHash FROM dbo.AspNetUsers WHERE Email = @Email or UserName = @Email’;
const query1 = ‘SELECT ClaimType, ClaimValue FROM dbo.AspNetUserClaims WHERE UserId = @UserId and (ClaimType=@Idr or ClaimType=@Idc or ClaimType=@Ecode)’;

we have tried to add the user parameter in the login code and console logs for errors
when we have checked the logs the data for the user is there but the user is still unable to access the application through the username

does any one know why its not working