innerLogin method
Implementation
Future<String?> innerLogin() async {
await loginObj!.initializationDone;
if (isInLoginRequest || loginObj == null) return null;
isInLoginRequest = true;
token = null;
sessionLink = 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'];
sessionLink = json['sessionLink']; // absent when the device is silenced
readConfig(ConfigResponse.fromJson(json['config']));
// eventEmitter.emit(CONNECTED);
Storage().setString('config', jsonEncode(json['config']));
return json['sessionUrl'];
} else if (resp.statusCode >= 400 && resp.statusCode < 500) {
// 4xx on loginSdk = integration error (bad appId/appKey, app deleted). Retrying won't help — caller must fix the integration.
InnerLog().e('loginSdk rejected with ${resp.statusCode} — check appId/appKey. Will not retry. body: ${resp.body}');
return null;
} 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;
}