diff --git a/framework/saleor/auth/use-signup.tsx b/framework/saleor/auth/use-signup.tsx index 9ca5c682f..d9943030f 100644 --- a/framework/saleor/auth/use-signup.tsx +++ b/framework/saleor/auth/use-signup.tsx @@ -4,7 +4,7 @@ import { CommerceError, ValidationError } from '@commerce/utils/errors' import useSignup, { UseSignup } from '@commerce/auth/use-signup' import useCustomer from '../customer/use-customer' import { - CustomerCreateInput, + CustomerCreate, Mutation, MutationCustomerCreateArgs, } from '../schema' @@ -17,17 +17,26 @@ export default useSignup as UseSignup export const handler: MutationHook< null, {}, - CustomerCreateInput, - CustomerCreateInput + CustomerCreate, + CustomerCreate > = { fetchOptions: { query: customerCreateMutation, }, async fetcher({ - input: { firstName, lastName, email, password }, + input: { user }, options, fetch, }) { + if (!user) { + throw new CommerceError({ + message: + 'A first name, last name, email and password are required to signup', + }) + } + + const { firstName, lastName, email, password } = user; + if (!(firstName && lastName && email && password)) { throw new CommerceError({ message: @@ -50,7 +59,7 @@ export const handler: MutationHook< }, }) - throwUserErrors(customerCreate?.customerUserErrors) + throwUserErrors(customerCreate?.errors) await handleAutomaticLogin(fetch, { email, password }) return null diff --git a/framework/saleor/utils/mutations/associate-customer-with-checkout.ts b/framework/saleor/utils/mutations/associate-customer-with-checkout.ts index 6b1350e05..61179ac59 100644 --- a/framework/saleor/utils/mutations/associate-customer-with-checkout.ts +++ b/framework/saleor/utils/mutations/associate-customer-with-checkout.ts @@ -1,5 +1,5 @@ const associateCustomerWithCheckoutMutation = /* GraphQl */ ` -mutation associateCustomerWithCheckout($checkoutId: ID!, $customerAccessToken: String!) { + mutation associateCustomerWithCheckout($checkoutId: ID!, $customerAccessToken: String!) { checkoutCustomerAssociateV2(checkoutId: $checkoutId, customerAccessToken: $customerAccessToken) { checkout { id diff --git a/framework/saleor/utils/mutations/customer-create.ts b/framework/saleor/utils/mutations/customer-create.ts index 05c728a25..440141a81 100644 --- a/framework/saleor/utils/mutations/customer-create.ts +++ b/framework/saleor/utils/mutations/customer-create.ts @@ -1,7 +1,7 @@ const customerCreateMutation = /* GraphQL */ ` - mutation customerCreate($input: CustomerCreateInput!) { + mutation customerCreate($input: UserCreateInput!) { customerCreate(input: $input) { - customerUserErrors { + errors { code field message