mirror of
https://github.com/vercel/commerce.git
synced 2025-06-15 03:41:21 +00:00
* Update product types * Cart types progress, add zod & initial schema validator * Update normalize.ts * Update with-schema-parser.ts * Updated types, schemas & providers * Fix providers after schema parse errors * Fix paths * More provider fixes * Fix kibocommerce & commercejs * Add customer updated types & fixes * Add checkout & customer types * Import core types only from commerce * Update tsconfig.json * Convert hooks interfaces to types * Requested changes * Change to relative paths * Move Zod dependency
36 lines
977 B
TypeScript
36 lines
977 B
TypeScript
import { useCallback } from 'react'
|
|
import type { MutationHook } from '@vercel/commerce/utils/types'
|
|
import useLogout, { type UseLogout } from '@vercel/commerce/auth/use-logout'
|
|
import useCustomer from '../customer/use-customer'
|
|
import type { LogoutMutation } from '../../schema'
|
|
import { logoutMutation } from '../utils/mutations/log-out-mutation'
|
|
import type { LogoutHook } from '@vercel/commerce/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]
|
|
)
|
|
},
|
|
}
|