mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 04:01:23 +00:00
start customer auth & signup
This commit is contained in:
@@ -2,18 +2,17 @@ import type { HookFetcher } from '@commerce/utils/types'
|
||||
import type { SwrOptions } from '@commerce/utils/use-data'
|
||||
import useCommerceCustomer from '@commerce/use-customer'
|
||||
|
||||
const defaultOpts = {}
|
||||
|
||||
export type Customer = {
|
||||
entityId: number
|
||||
firstName: string
|
||||
lastName: string
|
||||
email: string
|
||||
const defaultOpts = {
|
||||
query: '/api/bigcommerce/customers',
|
||||
}
|
||||
export type CustomerData = {}
|
||||
|
||||
export const fetcher: HookFetcher<Customer | null> = async () => {
|
||||
return null
|
||||
export const fetcher: HookFetcher<Customer | null> = async (
|
||||
options,
|
||||
_,
|
||||
fetch
|
||||
) => {
|
||||
const data = await fetch<CustomerData | null>({ ...defaultOpts, ...options })
|
||||
return data?.customer ?? null
|
||||
}
|
||||
|
||||
export function extendHook(
|
||||
@@ -21,7 +20,10 @@ export function extendHook(
|
||||
swrOptions?: SwrOptions<Customer | null>
|
||||
) {
|
||||
const useCustomer = () => {
|
||||
return { data: { firstName: null, lastName: null, email: null } }
|
||||
return useCommerceCustomer(defaultOpts, [], customFetcher, {
|
||||
revalidateOnFocus: false,
|
||||
...swrOptions,
|
||||
})
|
||||
}
|
||||
|
||||
useCustomer.extend = extendHook
|
||||
|
Reference in New Issue
Block a user