mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 15:36:58 +00:00
- Extended motlin sdk and corrected pcm ur - Using new client for below sections - Get all products - Get product - Get all products path - Login & Signup - Customers - Changing product normalizer for pcm products
43 lines
1.2 KiB
TypeScript
43 lines
1.2 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'
|
|
import epClient from '../utils/ep-client'
|
|
|
|
export default useSignup as UseSignup<typeof handler>
|
|
|
|
export const handler: MutationHook<any> = {
|
|
fetchOptions: {
|
|
query: '',
|
|
},
|
|
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',
|
|
})
|
|
}
|
|
|
|
const data = await epClient.Customers.Create({
|
|
email,
|
|
type: "customer",
|
|
name: `${firstName} ${lastName}`,
|
|
password });
|
|
return data || null;
|
|
},
|
|
useHook: ({ fetch }) => () => {
|
|
const { revalidate } = useCustomer()
|
|
|
|
return useCallback(
|
|
async function signup(input) {
|
|
const data = await fetch({ input })
|
|
await revalidate()
|
|
return data
|
|
},
|
|
[fetch, revalidate]
|
|
)
|
|
},
|
|
}
|