autoNavigate method

Future<void> autoNavigate()

Implementation

Future<void> autoNavigate() async {
  if (config.handlers == null) return;

  final authenticated = authState.isAuthenticated;
  bool? isFirstTime;
  if (!authenticated) {
    isFirstTime = await CkAuthStorageKeys.isFirstTimeUser();
  }

  void navigate() {
    if (authenticated) {
      config.handlers!.onAuthenticated();
    } else {
      if (config.handlers!.showOnboarding != null) {
        final showOnboarding =
            !config.handlers!.firstTimeOnly || (isFirstTime ?? true);
        if (showOnboarding) {
          config.handlers!.showOnboarding!();
        } else {
          config.handlers!.showLogin();
        }
      } else {
        config.handlers!.showLogin();
      }
    }
  }

  try {
    navigate();
  } catch (_) {
    Future.delayed(const Duration(milliseconds: 100), navigate);
  }
}