public async Task <IActionResult> Authenticate(Login login) { try { var userAuthenticate = await _supervisor.Authenticate(login.username, login.password); if (userAuthenticate == null) { _logger.LogWarning("Error in Authenticate: username [{Username}] not registered or incorrect password", login.username); return(BadRequest(new { message = "Username or password is incorrect" })); } return(new ObjectResult(new Session { user = new UserViewModel { id = userAuthenticate.id, name = userAuthenticate.name, username = userAuthenticate.username, email = userAuthenticate.email, surname = userAuthenticate.surname, birthDate = userAuthenticate.birthDate }, token = userAuthenticate.token })); } catch (Exception ex) { _logger.LogError(ex, "Exception: "); return(StatusCode(500, ex)); } }