setUserId method

Future<LinkFiveActiveProducts> setUserId(
  1. String? userId
)

Customer User Id

We also update LinkFive and change the userId if different.

Implementation

Future<LinkFiveActiveProducts> setUserId(String? userId) async {
  await waitForInit();
  final previousUserId = appDataStore.userId;
  appDataStore.userId = userId;

  LinkFiveLogger.d("Set user ID to $userId");

  // If the userId is different than before
  // do the LinkFive request
  if (userId != previousUserId) {
    LinkFiveLogger.d("User Id has changed since last time update LinkFive");
    final LinkFiveActiveProducts activeProducts = await _client.changeUserId(userId);

    // notify all listeners
    _store.onNewLinkFiveNewActiveProducts(activeProducts);

    // update purchase State
    super.updateStateFromActiveProducts(activeProducts);

    return activeProducts;
  }
  return _store.latestLinkFiveActiveProducts ?? LinkFiveActiveProducts.empty();
}