mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
setup custom fetcher and auth hooks
This commit is contained in:
@@ -1,20 +1,25 @@
|
||||
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
|
||||
import { Customer } from '@commerce/types'
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import { getCustomerQuery, getCustomerToken } from '../utils'
|
||||
import { normalizeCustomer } from '../utils/normalize'
|
||||
// import { getCustomerQuery, getCustomerToken } from '../utils'
|
||||
|
||||
export default useCustomer as UseCustomer<typeof handler>
|
||||
|
||||
export const handler: SWRHook<Customer | null> = {
|
||||
fetchOptions: {
|
||||
query: getCustomerQuery,
|
||||
query: 'account',
|
||||
method: 'get',
|
||||
},
|
||||
async fetcher({ options, fetch }) {
|
||||
// console.log('STORE_ID', STORE_ID, 'PUBLIC_KEY', PUBLIC_KEY);
|
||||
// const data = await swell.account.get()
|
||||
const data = await fetch<any | null>({
|
||||
...options,
|
||||
variables: { customerAccessToken: getCustomerToken() },
|
||||
// variables: { customerAccessToken: getCustomerToken() },
|
||||
})
|
||||
return data.customer ?? null
|
||||
console.log(`Customer data ${data}`)
|
||||
return data ? normalizeCustomer(data) : null
|
||||
},
|
||||
useHook: ({ useData }) => (input) => {
|
||||
return useData({
|
||||
@@ -25,3 +30,26 @@ export const handler: SWRHook<Customer | null> = {
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
// const handler = (): { data: Customer } => {
|
||||
// const swell = getContext();
|
||||
// const response = swell.account.get();
|
||||
// const { firstName, lastName, email, company, customerGroupId, notes, phone,
|
||||
// entityId, addressCount, attributeCount, storeCredit } = response;
|
||||
// return {
|
||||
// data: {
|
||||
// firstName,
|
||||
// lastName,
|
||||
// email,
|
||||
// company,
|
||||
// customerGroupId,
|
||||
// notes,
|
||||
// phone,
|
||||
// entityId,
|
||||
// addressCount,
|
||||
// attributeCount,
|
||||
// storeCredit
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// export default handler;
|
||||
|
Reference in New Issue
Block a user