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
36 lines
941 B
TypeScript
36 lines
941 B
TypeScript
import { SWRHook } from '@commerce/utils/types'
|
|
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
|
|
import getCustomerCookie from '../utils/get-customer-creds'
|
|
import epClient from '../utils/ep-client'
|
|
|
|
export default useCustomer as UseCustomer<typeof handler>
|
|
export const handler: SWRHook<any> = {
|
|
fetchOptions: {
|
|
query: '',
|
|
},
|
|
async fetcher() {
|
|
const creds = getCustomerCookie();
|
|
|
|
// if user is not logged-in return null
|
|
if(!creds) {
|
|
return null;
|
|
}
|
|
console.log('moltin sdk', epClient);
|
|
const {data:customer} = await epClient.Customers.Get(creds.customer_id, creds.token);
|
|
|
|
return {
|
|
...customer,
|
|
firstName: customer.name.split(" ")[0],
|
|
lastName: customer.name.split(" ")[1]
|
|
}
|
|
},
|
|
useHook: ({ useData }) => (input) => {
|
|
return useData({
|
|
swrOptions: {
|
|
revalidateOnFocus: false,
|
|
...input?.swrOptions,
|
|
},
|
|
})
|
|
},
|
|
}
|