mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 23:46:58 +00:00
30 lines
829 B
TypeScript
30 lines
829 B
TypeScript
import { useCallback } from 'react'
|
|
import type { MutationHook } from '@commerce/utils/types'
|
|
import useLogout, { UseLogout } from '@commerce/auth/use-logout'
|
|
import type { LogoutHook } from '../types/logout'
|
|
import useCustomer from '../customer/use-customer'
|
|
import useCart from '../cart/use-cart'
|
|
|
|
export default useLogout as UseLogout<typeof handler>
|
|
|
|
export const handler: MutationHook<LogoutHook> = {
|
|
fetchOptions: {
|
|
url: '/api/logout',
|
|
method: 'GET',
|
|
},
|
|
useHook: ({ fetch }) => () => {
|
|
const { mutate } = useCustomer()
|
|
const { mutate: mutateCart } = useCart()
|
|
|
|
return useCallback(
|
|
async function logout() {
|
|
const data = await fetch()
|
|
await mutate(null, false)
|
|
await mutateCart(null, false)
|
|
return data
|
|
},
|
|
[fetch, mutate, mutateCart]
|
|
)
|
|
},
|
|
}
|