mirror of
https://github.com/vercel/commerce.git
synced 2025-03-27 07:45:53 +00:00
34 lines
898 B
TypeScript
34 lines
898 B
TypeScript
import { useCallback } from 'react'
|
|
import { MutationHook } from '@commerce/utils/types'
|
|
import useLogout, { UseLogout } from '@commerce/auth/use-logout'
|
|
import useCustomer from '../customer/use-customer'
|
|
import { LogoutMutation } from '../schema'
|
|
import { logoutMutation } from '../utils/mutations/log-out-mutation'
|
|
import { LogoutHook } from '../types/logout'
|
|
|
|
export default useLogout as UseLogout<typeof handler>
|
|
|
|
export const handler: MutationHook<LogoutHook> = {
|
|
fetchOptions: {
|
|
query: logoutMutation,
|
|
},
|
|
async fetcher({ options, fetch }) {
|
|
await fetch<LogoutMutation>({
|
|
...options,
|
|
})
|
|
return null
|
|
},
|
|
useHook: ({ fetch }) => () => {
|
|
const { mutate } = useCustomer()
|
|
|
|
return useCallback(
|
|
async function logout() {
|
|
const data = await fetch()
|
|
await mutate(null, false)
|
|
return data
|
|
},
|
|
[fetch, mutate]
|
|
)
|
|
},
|
|
}
|