innerLogin method

Future<String?> innerLogin()

Implementation

Future<String?> innerLogin() async {
  await loginObj!.initializationDone;
  if (isInLoginRequest || loginObj == null) return null;

  isInLoginRequest = true;
  token = null;
  try {
    var loginObjData = loginObj!.toJson();
    InnerLog().d('loginObjData: $loginObjData');

    var resp = await ConnectionClient.request('auth/loginSdk', loginObjData, HttpMethod.post);
    InnerLog().d('resp: $resp');
    isInLoginRequest = false;

    if (resp.statusCode >= 200 && resp.statusCode < 300) {
      var json = jsonDecode(resp.body);
      InnerLog().i('Succeeded!: $json');
      token = json['token'];

      readConfig(ConfigResponse.fromJson(json['config']));

      // eventEmitter.emit(CONNECTED);
      Storage().setString('config', jsonEncode(json['config']));

      return json['sessionUrl'];
    } else {
      InnerLog().e('didn\'t succeed to log');
      var text = resp.body;
      if (text.isNotEmpty) {
        InnerLog().e('the info that was received: $text');
      }
      return null;
    }
  } catch (e) {
    InnerLog().e('there was an error with the request: $e');
  }
  return null;
}