currentUser method

Future<ShopifyUser?> currentUser()

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

Implementation

Future<ShopifyUser?> currentUser() async {
  final WatchQueryOptions _getCustomer = WatchQueryOptions(
    document: gql(getCustomerQuery),
    variables: {'customerAccessToken': await currentCustomerAccessToken},
    fetchPolicy: FetchPolicy.networkOnly,
  );
  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;
  }
}