createUserWithEmailAndPassword method
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. countrycode
number 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;
}