currentUser method

Future<ShopifyUser?> currentUser({
  1. bool deleteThisPartOfCache = false,
})

Returns the currently signed-in ShopifyUser or null if there is none.

Implementation

Future<ShopifyUser?> currentUser({bool deleteThisPartOfCache = false}) async {
  final WatchQueryOptions _getCustomer = WatchQueryOptions(
      document: gql(getCustomerQuery),
      variables: {'customerAccessToken': await currentCustomerAccessToken});
  if (deleteThisPartOfCache) {
    _graphQLClient!.cache.writeQuery(_getCustomer.asRequest, data: {});
  }
  if (_shopifyUser.containsKey(ShopifyConfig.storeUrl)) {
    return _shopifyUser[ShopifyConfig.storeUrl];
  } else if (await currentCustomerAccessToken != null) {
    final QueryResult result = (await _graphQLClient!.query(_getCustomer));
    checkForError(result);
    ShopifyUser user = ShopifyUser.fromGraphJson(
        (result.data ?? const {})['customer'] ?? const {});
    return user;
  } else {
    return null;
  }
}