login method

Future<String?> login(
  1. String appId,
  2. String appKey
)

Implementation

Future<String?> login(String appId, String appKey) async {
  this.appId = appId;
  this.appKey = appKey;
  loginObj = Login(appId, appKey);

  ConfigResponse config;
  try {
    config = ConfigResponse.fromJson(jsonDecode(Storage().getString('config') ?? defaultConfig));
  } catch (e) {
    // A corrupt cached config must never block login, otherwise the SDK stays silent until app data is cleared.
    InnerLog().w('cached config is corrupt, deleting it and falling back to the default config: $e');
    Storage().remove('config');
    config = ConfigResponse.fromJson(jsonDecode(defaultConfig));
  }
  readConfig(config);

  final savedPause = Storage().getString(_pauseKey);
  pausedUntil = null;
  try {
    final pause = jsonDecode(savedPause ?? '{}');
    if (pause['appId'] == appId && pause['sdkVersion'] == Login.currentSdkVersion) {
      pausedUntil = DateTime.fromMillisecondsSinceEpoch(pause['until']);
    }
  } catch (e) {
    InnerLog().w('saved pause is corrupt, deleting it: $e');
  }
  if (paused && !pausedUntil!.isAfter(DateTime.now().add(_maxPause))) {
    InnerLog().w('paused until ${pausedUntil!.toUtc().toIso8601String()} (from an earlier run); nothing will be sent');
  } else if (savedPause != null) {
    pausedUntil = null;
    Storage().remove(_pauseKey);
  }
  return await innerLogin();
}