mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 07:26:59 +00:00
- Changed the loging fetch - Store the token and user id in cookie - Ue the cookie to make user calls like get user
29 lines
696 B
TypeScript
29 lines
696 B
TypeScript
import { MutationHook } from '@commerce/utils/types'
|
|
import useLogout, { UseLogout } from '@commerce/auth/use-logout'
|
|
import Cookies from 'js-cookie'
|
|
|
|
export default useLogout as UseLogout<typeof handler>
|
|
import useCustomer from '../customer/use-customer'
|
|
import { useCallback } from 'react'
|
|
|
|
export const handler: MutationHook<any> = {
|
|
fetchOptions: {
|
|
query: '?',
|
|
},
|
|
async fetcher() {
|
|
Cookies.remove("user_token");
|
|
},
|
|
useHook: ({ fetch }) => () => {
|
|
const { mutate } = useCustomer()
|
|
|
|
return useCallback(
|
|
async function logout() {
|
|
const data = await fetch()
|
|
await mutate(null, false)
|
|
return data
|
|
},
|
|
[fetch, mutate]
|
|
)
|
|
},
|
|
}
|