mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 20:21:22 +00:00
.vscode
assets
components
config
framework
bigcommerce
commerce
local
saleor
shopify
swell
api
auth
use-login.tsx
use-logout.tsx
use-signup.tsx
cart
customer
product
types
utils
wishlist
.env.template
commerce.config.json
const.ts
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
types.ts
vendure
lib
pages
public
theme
.editorconfig
.env.template
.gitignore
.prettierignore
.prettierrc
README.md
codegen.bigcommerce.json
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package.json
postcss.config.js
swell-js.d.ts
tailwind.config.js
tsconfig.json
yarn.lock
* fix update cart item * update types * update checkout * update get-page, cleanup types * revert change to incorrect file * cleanup Co-authored-by: Greg Hoskin <greghoskin@Gregs-MacBook-Pro.local>
38 lines
973 B
TypeScript
38 lines
973 B
TypeScript
import { useCallback } from 'react'
|
|
import type { MutationHook } from '@commerce/utils/types'
|
|
import useLogout, { UseLogout } from '@commerce/auth/use-logout'
|
|
import useCustomer from '../customer/use-customer'
|
|
import { getCustomerToken, setCustomerToken } from '../utils/customer-token'
|
|
import { LogoutHook } from '../types/logout'
|
|
|
|
export default useLogout as UseLogout<typeof handler>
|
|
|
|
export const handler: MutationHook<LogoutHook> = {
|
|
fetchOptions: {
|
|
query: 'account',
|
|
method: 'logout',
|
|
},
|
|
async fetcher({ options, fetch }) {
|
|
await fetch({
|
|
...options,
|
|
variables: {
|
|
customerAccessToken: getCustomerToken(),
|
|
},
|
|
})
|
|
setCustomerToken(null)
|
|
return null
|
|
},
|
|
useHook: ({ fetch }) => () => {
|
|
const { mutate } = useCustomer()
|
|
|
|
return useCallback(
|
|
async function logout() {
|
|
const data = await fetch()
|
|
await mutate(null, false)
|
|
return data
|
|
},
|
|
[fetch, mutate]
|
|
)
|
|
},
|
|
}
|