createUserWithEmailAndPassword method

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

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,
  required String phone,
  String? firstName,
  String? lastName,
  bool? acceptsMarketing,
}) 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;
}