currentCustomerAccessToken property

Future<String?> get currentCustomerAccessToken

Returns the current customer access token.

If the current access token is not expired but about to expire, it will renew the token.

The token is considered about to expire if the difference between the current time and the token's expiration time is less than 10 minutes.

The token is considered expired if the current time is after the token's expiration time.

If the token is expired, it will return null.

If the token is not expired, it will return the token.

Implementation

Future<String?> get currentCustomerAccessToken async {
  final data = await accessTokenWithExpDate;
  final String? accessToken = data?.accessToken;
  if (await _isTokenNotExpiredButAboutToExpire(data)) {
    try {
      final updatedAccessToken = await _renewAccessToken(
        accessToken!,
      );
      await _setShopifyUser(
        updatedAccessToken,
        _shopifyUser[ShopifyConfig.storeUrl],
      );
      return updatedAccessToken.accessToken;
    } catch (e) {
      log('Error renewing token: $e');
    }
  }
  return accessToken;
}