Moved use-login and use-logout

This commit is contained in:
Luis Alvarez
2021-02-19 19:43:15 -05:00
parent aa227e3de2
commit 7cd64d2c2a
9 changed files with 95 additions and 81 deletions

View File

@@ -1,38 +1,25 @@
import { useCallback } from 'react'
import type { HookFetcher } from '@commerce/utils/types'
import useCommerceLogout from '@commerce/use-logout'
import type { MutationHook } from '@commerce/utils/types'
import useLogout, { UseLogout } from '@commerce/use-logout'
import useCustomer from '../customer/use-customer'
const defaultOpts = {
url: '/api/bigcommerce/customers/logout',
method: 'GET',
}
export default useLogout as UseLogout<typeof handler>
export const fetcher: HookFetcher<null> = (options, _, fetch) => {
return fetch({
...defaultOpts,
...options,
})
}
export function extendHook(customFetcher: typeof fetcher) {
const useLogout = () => {
export const handler: MutationHook<null> = {
fetchOptions: {
url: '/api/bigcommerce/customers/logout',
method: 'GET',
},
useHook: ({ fetch }) => () => {
const { mutate } = useCustomer()
const fn = useCommerceLogout<null>(defaultOpts, customFetcher)
return useCallback(
async function login() {
const data = await fn(null)
async function logout() {
const data = await fetch()
await mutate(null, false)
return data
},
[fn]
[fetch, mutate]
)
}
useLogout.extend = extendHook
return useLogout
},
}
export default extendHook(fetcher)