I am trying to add authentication and authorization to my API in .NET core 2.1. Everything worked perfectly well. However, when I try to sign In a user, I get this error in my testing environment: "An exception occurred while reading a database value for property 'IdentityUser.Id'. The expected type was 'System.String' but the actual value was of type 'System.Guid'".
I have tried overriding the data type of the id to string but nothing worked for me. I have also tried dropping the tables and recreating and none worked.
ApplicationUser Model:
public class ApplicationUser : IdentityUser
{
public override string Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
This is how I am signing the user in:
public async Task<object> Login ([FromBody] LoginModel model)
{
try
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
//use signin manager to handle user sign in
//the error shows up in this method
var signin = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false, false);
if (signin.Succeeded)
{
var appuser = _userManager.Users.SingleOrDefault(u => u.Email == model.Email);
return await GenerateJwtToken(model.Email, appuser);
}
}
catch(Exception ex)
{
return ex.Message;
}
throw new ApplicationException("INVALID LOGIN ATTEMPT");
// return BadRequest("no login detail found");
}
This is my login model
public class LoginModel
{
[Required]
public string Email { get; set; }
[Required]
public string Password { get; set; }
}
I am aware that the default type of identityuser.id is guid and I want to be able to convert/override it to string so that it conforms with my requirement