mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 23:46:58 +00:00
add logout
Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
parent
8f260d66e7
commit
12a96103a8
@ -2,21 +2,18 @@ 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 customerAccessTokenDeleteMutation from '../utils/mutations/customer-access-token-delete'
|
||||
import logoutMutation from '../utils/mutations/logout'
|
||||
import { getCustomerToken, setCustomerToken } from '../utils/customer-token'
|
||||
|
||||
export default useLogout as UseLogout<typeof handler>
|
||||
|
||||
export const handler: MutationHook<null> = {
|
||||
fetchOptions: {
|
||||
query: customerAccessTokenDeleteMutation,
|
||||
query: logoutMutation,
|
||||
},
|
||||
async fetcher({ options, fetch }) {
|
||||
await fetch({
|
||||
...options,
|
||||
variables: {
|
||||
customerAccessToken: getCustomerToken(),
|
||||
},
|
||||
})
|
||||
setCustomerToken(null)
|
||||
return null
|
||||
|
@ -33,7 +33,7 @@ const fetcher: Fetcher = async ({
|
||||
const authorizationHeader = {}
|
||||
|
||||
if (customerToken) {
|
||||
authorizationHeader['Authorization'] = `bearer ${customerToken}`
|
||||
authorizationHeader['Authorization'] = `Bearer ${customerToken}`
|
||||
}
|
||||
|
||||
return handleFetchResponse(
|
||||
|
@ -1,14 +0,0 @@
|
||||
const customerAccessTokenDeleteMutation = /* GraphQL */ `
|
||||
mutation customerAccessTokenDelete($customerAccessToken: String!) {
|
||||
customerAccessTokenDelete(customerAccessToken: $customerAccessToken) {
|
||||
deletedAccessToken
|
||||
deletedCustomerAccessTokenId
|
||||
userErrors {
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
export default customerAccessTokenDeleteMutation
|
@ -2,6 +2,6 @@ export { default as addCartItemsMutation } from './add-cart-items'
|
||||
export { default as customerCreateMutation } from './customer-create'
|
||||
export { default as checkoutCreateMutation } from './checkout-create'
|
||||
export { default as authenticateMutation } from './authenticate'
|
||||
export { default as customerAccessTokenDeleteMutation } from './customer-access-token-delete'
|
||||
export { default as logoutMutation } from './logout'
|
||||
export { default as removeCartItemsMutation } from './remove-cart-items'
|
||||
export { default as updateCartItemsQuantityMutation } from './update-cart-items-quantity'
|
||||
|
7
framework/reactioncommerce/utils/mutations/logout.ts
Normal file
7
framework/reactioncommerce/utils/mutations/logout.ts
Normal file
@ -0,0 +1,7 @@
|
||||
const logoutMutation = /* GraphQL */ `
|
||||
mutation logout {
|
||||
logout
|
||||
}
|
||||
`
|
||||
|
||||
export default logoutMutation
|
Loading…
x
Reference in New Issue
Block a user