getUserInfo method

Future<WooCustomer?> getUserInfo(
  1. String email
)

Implementation

Future<WooCustomer?> getUserInfo(String email) async {
  final authToken = base64.encode(utf8.encode('$username:$password'));
  dio.options.headers = {HttpHeaders.authorizationHeader: 'Basic $authToken'};
  dio.options.baseUrl = FlutterWooCommerce.url;
  try {
    final response = await dio.get(
      _AuthenticationEndpoints.getUserInfo,
      queryParameters: {'email': email, 'context': WooContext.view.name},
    );
    final responseData = response.data as List<dynamic>;
    if (responseData.isEmpty) {
      throw Exception('User not found');
    }
    final user = responseData.first;
    final customer = WooCustomer.fromJson(user as Map<String, dynamic>);
    // await LocalStorageHelper.updateSecurityUserId(userId);
    return customer;
  } on DioException catch (e) {
    final errorMsg = e.response?.data['message'] ?? e.message;
    throw Exception('Failed to get user info: $errorMsg');
  } catch (e) {
    throw Exception('Unexpected error getting user info: ${e.toString()}');
  }
}