vijayakumarv-trika 045f6bcc75 Code changes
2021-08-05 16:12:04 +05:30

46 lines
1.1 KiB
TypeScript

import { useCallback } from 'react'
import useCustomer from '../customer/use-customer'
import { MutationHook } from '@commerce/utils/types'
import { CommerceError } from '@commerce/utils/errors'
import useSignup, { UseSignup } from '@commerce/auth/use-signup'
export default useSignup as UseSignup<typeof handler>
export const handler: MutationHook<any> = {
fetchOptions: {
url: '/api/signup',
method: 'POST',
},
async fetcher({ input: { firstName, lastName, email, password }, options, fetch }) {
console.log("input", firstName)
if (!(firstName && lastName && email && password)) {
throw new CommerceError({
message:
'A first name, last name, email and password are required to login',
})
}
return fetch({
...options,
variables: {
firstName,
lastName,
email,
password
},
});
},
useHook: ({ fetch }) => () => {
const { revalidate } = useCustomer()
return useCallback(
async function signup(input) {
const data = await fetch({ input })
await revalidate()
return data
},
[fetch, revalidate]
)
},
}