createOrUpdate method

Future<User> createOrUpdate({
  1. bool? isTrial,
  2. bool? isPremium,
  3. DateTime? firstSeenAt,
  4. Map<String, dynamic>? metadata,
  5. String? stripeCustomerId,
})

Creates the user if missing, or updates the existing one.

Returns the updated User.

Implementation

Future<User> createOrUpdate({
  bool? isTrial,
  bool? isPremium,
  DateTime? firstSeenAt,
  Map<String, dynamic>? metadata,
  String? stripeCustomerId,
}) async {
  final request = UserCreateRequest((b) => b
    ..appUserId = appUserId
    ..isTrial = isTrial
    ..isPremium = isPremium
    ..firstSeenAt = firstSeenAt
    ..metadata = metadata == null ? null : JsonObject(metadata)
    ..stripeCustomerId = stripeCustomerId);
  final response = await _sdk._users.createOrUpdateUser(
    xApiKey: _sdk.apiKey,
    userCreateRequest: request,
  );
  final body = response.data ??
      (throw StateError('createOrUpdate: response body was empty.'));
  return body.data.user;
}