signInWithEmail method

Future<AccessToken> signInWithEmail(
  1. String? username,
  2. String? password
)

Implementation

Future<AccessToken> signInWithEmail(
    String? username, String? password) async {
  AuthenticationApi authenticationApi = AuthenticationApi(authAPIClient);
  var accessTokenRequest = AccessTokenRequest();
  accessTokenRequest.clientId = APIConstants.clientID;
  accessTokenRequest.clientSecret = APIConstants.clientSecret;
  accessTokenRequest.grantType = APIConstants.userGrantType;

  var accessTokenPayload = AccessTokenPayload();
  accessTokenPayload.provider = "email";
  accessTokenPayload.identifier = username;
  accessTokenPayload.password = password;
  accessTokenRequest.payload = accessTokenPayload;
  var response = authenticationApi.getAccessToken(accessTokenRequest);
  return response.then((value) {
    updateClientsWithUserAccessToken(value);
    _saveValueToSharedPreferences("user_identifier", username);

    userIdentifier = username;
    UserApi userApi = UserApi();
    userApi.getMyProfile().then((profileResponse) {
      currentUser = profileResponse.data;
    }).catchError((error) {
      if (kDebugMode) {
        print(error);
      }
    });
    return value;
  });
}