mirror of
https://github.com/vercel/commerce.git
synced 2025-06-20 06:01:21 +00:00
saleor: preliminary signup process
This commit is contained in:
parent
7d80fadd82
commit
7524f5ab2e
@ -4,7 +4,7 @@ import { CommerceError, ValidationError } from '@commerce/utils/errors'
|
|||||||
import useSignup, { UseSignup } from '@commerce/auth/use-signup'
|
import useSignup, { UseSignup } from '@commerce/auth/use-signup'
|
||||||
import useCustomer from '../customer/use-customer'
|
import useCustomer from '../customer/use-customer'
|
||||||
import {
|
import {
|
||||||
CustomerCreateInput,
|
CustomerCreate,
|
||||||
Mutation,
|
Mutation,
|
||||||
MutationCustomerCreateArgs,
|
MutationCustomerCreateArgs,
|
||||||
} from '../schema'
|
} from '../schema'
|
||||||
@ -17,17 +17,26 @@ export default useSignup as UseSignup<typeof handler>
|
|||||||
export const handler: MutationHook<
|
export const handler: MutationHook<
|
||||||
null,
|
null,
|
||||||
{},
|
{},
|
||||||
CustomerCreateInput,
|
CustomerCreate,
|
||||||
CustomerCreateInput
|
CustomerCreate
|
||||||
> = {
|
> = {
|
||||||
fetchOptions: {
|
fetchOptions: {
|
||||||
query: customerCreateMutation,
|
query: customerCreateMutation,
|
||||||
},
|
},
|
||||||
async fetcher({
|
async fetcher({
|
||||||
input: { firstName, lastName, email, password },
|
input: { user },
|
||||||
options,
|
options,
|
||||||
fetch,
|
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)) {
|
if (!(firstName && lastName && email && password)) {
|
||||||
throw new CommerceError({
|
throw new CommerceError({
|
||||||
message:
|
message:
|
||||||
@ -50,7 +59,7 @@ export const handler: MutationHook<
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
throwUserErrors(customerCreate?.customerUserErrors)
|
throwUserErrors(customerCreate?.errors)
|
||||||
await handleAutomaticLogin(fetch, { email, password })
|
await handleAutomaticLogin(fetch, { email, password })
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
const customerCreateMutation = /* GraphQL */ `
|
const customerCreateMutation = /* GraphQL */ `
|
||||||
mutation customerCreate($input: CustomerCreateInput!) {
|
mutation customerCreate($input: UserCreateInput!) {
|
||||||
customerCreate(input: $input) {
|
customerCreate(input: $input) {
|
||||||
customerUserErrors {
|
errors {
|
||||||
code
|
code
|
||||||
field
|
field
|
||||||
message
|
message
|
||||||
|
Loading…
x
Reference in New Issue
Block a user