0
/// Mutation to create a customer
const String customerCreateMutation = r'''
mutation MyMutation($firstName: String, $lastName: String, $email: String!, $password: String!, $acceptsMarketing: Boolean, $phone: String) {
  customerCreate(input: {firstName: $firstName, lastName: $lastName, email: $email, password: $password, acceptsMarketing: $acceptsMarketing, phone: $phone}) {
    customer{
      acceptsMarketing
    addresses(first: 10) {
      edges {
        node {
          address1
          address2
          city
          company
          country
          countryCodeV2
          firstName
          id
          lastName
          latitude
          longitude
          name
          phone
          province
          provinceCode
          zip
        }
      }
    }
    createdAt
    defaultAddress {
      address1
      address2
      city
      company
      country
      countryCodeV2
      firstName
      id
      lastName
      latitude
      longitude
      name
      phone
      province
      zip
      provinceCode
    }
    tags
    displayName
    email
    firstName
    id
    lastName
    phone
  }
  customerUserErrors {
      code
      field
      message
    }
  }
}
''';

Future<ShopifyUser> createUserWithEmailAndPassword({
    required String email,
    required String password,
    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;
  }

I am using this function to create users in shopify. This function works but there is a problem. I recieve an email You've activated your customer account. next time you shop with us... . The problem with this is that the account is activated immediatly regardless of verifying email. I have set my account settings to: Legacy Customers create an account and sign in with email and password.

It is absouloulty not ideal for an app that the that the email is not verified and is being used. More ever there is another setting

Customer accounts

Customers sign in with a one-time code sent to their email (no passwords). Works with B2B.

This method is recommended by shopify but I can't find the docs which shows how to create user with this method. Please I need guidance how to manage the store authentication flow.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.