add sign up hook

This commit is contained in:
DuvCharles 2023-01-17 17:44:43 +01:00 committed by Hadrien Lucas
parent 5b29bf8c78
commit daabb58fed

View File

@ -1,5 +1,4 @@
import { useCallback } from 'react'
import useCustomer from '../customer/use-customer'
import { MutationHook } from '@vercel/commerce/utils/types'
import useSignup, { UseSignup } from '@vercel/commerce/auth/use-signup'
@ -7,13 +6,37 @@ export default useSignup as UseSignup<typeof handler>
export const handler: MutationHook<any> = {
fetchOptions: {
query: '',
url: '/api/v2/shop/customers',
method: 'POST',
},
async fetcher() {
return null
fetcher: async ({
input: { firstName, lastName, email, password },
options,
fetch,
}) => {
await fetch({
url: options.url,
method: options.method,
body: {
firstName: firstName,
lastName: lastName,
email: email,
password: password,
subscribedToNewsletter: false,
},
variables: {
useToken: false,
},
})
},
useHook:
({ fetch }) =>
() =>
() => {},
() => {
return useCallback(
async function signup(input) {
await fetch({ input })
},
[fetch]
)
},
}