updateUser method

Future<void> updateUser({
  1. required String email,
  2. Map<String, dynamic>? userMeta,
})

Implementation

Future<void> updateUser({required String email, Map<String, dynamic>? userMeta}) async {
  final userId = await userService.getUserId();

  final Map<String, dynamic> payload = {'email': email};
  if (userMeta != null) {
    payload['userMeta'] = userMeta;
  }

  final response = await http.put(
    Uri.parse('${apiUrl}users/$userId'),
    headers: {
      'api-key': apiKey,
      'user-id': userId,
      "Content-Type": "application/json",
      "Accept": "application/json",
    },
    body: json.encode(payload),
  );

  if (response.statusCode == 201) {
    return;
  } else {
    throw Exception('Failed to update user');
  }
}