mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
initial provider (#2)
This commit is contained in:
committed by
GitHub
parent
5b4d1b57d4
commit
3342d9d1bb
27
framework/medusa/customer/use-customer.tsx
Normal file
27
framework/medusa/customer/use-customer.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
|
||||
import { normalizeCustomer } from '@framework/utils/normalizers/normalize-customer'
|
||||
|
||||
export default useCustomer as UseCustomer<typeof handler>
|
||||
export const handler: SWRHook<any> = {
|
||||
fetchOptions: {
|
||||
query: 'auth',
|
||||
method: 'getSession',
|
||||
},
|
||||
async fetcher({ options, fetch }) {
|
||||
const data = await fetch({
|
||||
...options,
|
||||
})
|
||||
return normalizeCustomer(data?.customer) || null
|
||||
},
|
||||
useHook:
|
||||
({ useData }) =>
|
||||
(input) => {
|
||||
return useData({
|
||||
swrOptions: {
|
||||
revalidateOnFocus: false,
|
||||
...input?.swrOptions,
|
||||
},
|
||||
})
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user