I'm seeing odd behavior with the login/logout routes. I have the front-end set up using React. When the Login button is clicked, it makes an ajax call to a route /login, which then runs the login function below:
[HttpPost]
public async Task<IActionResult> Post([FromBody] LoginModel loginModel) {
if (!ModelState.IsValid) {
return new BadRequestResult();
}
var signInResult = await SignInManager.PasswordSignInAsync(loginModel.Username, loginModel.Password, false, false);
if (signInResult.Succeeded) {
var currentUser = await UserManager.GetUserAsync(User);
if (currentUser == null) {
return new BadRequestResult();
}
var myUserModel = Mapper.Map<MyUser, MyUserModel>(currentUser);
return new OkObjectResult(myUserModel);
}
return new BadRequestResult();
}
The issue is that I have to click the button twice. The first time I click it, this function hits currentUser == null, so it returns a 400. But the second time I click it, it works just fine.
I am trying to login, then return the user object back to the front-end.