createUserWithEmailAndPassword method

Future<ShopifyUser> createUserWithEmailAndPassword({
  1. required String email,
  2. required String password,
  3. String? firstName,
  4. String? lastName,
  5. bool? acceptsMarketing,
  6. String? phone,
})

Tries to create a new user account with the given email address and password.

if phone is provided, it should be formatted using E.164 standard. For example, +16135551111. i.e. countrycodenumber including area code

Implementation

Future<ShopifyUser> createUserWithEmailAndPassword({
  required String email,
  required String password,
  String? firstName,
  String? lastName,
  bool? acceptsMarketing,
  String? phone,
}) async {
  final MutationOptions _options = MutationOptions(
    document: gql(customerCreateMutation),
    variables: {
      'firstName': firstName,
      'lastName': lastName,
      'email': email,
      'password': password,
      'acceptsMarketing': acceptsMarketing ?? false,
      'phone': phone,
    },
  );
  final QueryResult result = await _graphQLClient!.mutate(_options);
  checkForError(
    result,
    key: 'customerCreate',
    errorKey: 'customerUserErrors',
  );
  final shopifyUser = ShopifyUser.fromGraphJson(
      (result.data!['customerCreate'] ?? const {})['customer']);
  final AccessTokenWithExpDate accessTokenWithExpDate =
      await _createAccessToken(
    email,
    password,
  );
  await _setShopifyUser(
    accessTokenWithExpDate,
    shopifyUser,
  );
  return shopifyUser;
}