add logout

Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
Loan Laux 2021-04-23 20:56:55 +04:00
parent 8f260d66e7
commit 12a96103a8
No known key found for this signature in database
GPG Key ID: AF9E9BD6548AD52E
5 changed files with 11 additions and 21 deletions

View File

@ -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

View File

@ -33,7 +33,7 @@ const fetcher: Fetcher = async ({
const authorizationHeader = {}
if (customerToken) {
authorizationHeader['Authorization'] = `bearer ${customerToken}`
authorizationHeader['Authorization'] = `Bearer ${customerToken}`
}
return handleFetchResponse(

View File

@ -1,14 +0,0 @@
const customerAccessTokenDeleteMutation = /* GraphQL */ `
mutation customerAccessTokenDelete($customerAccessToken: String!) {
customerAccessTokenDelete(customerAccessToken: $customerAccessToken) {
deletedAccessToken
deletedCustomerAccessTokenId
userErrors {
field
message
}
}
}
`
export default customerAccessTokenDeleteMutation

View File

@ -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'

View File

@ -0,0 +1,7 @@
const logoutMutation = /* GraphQL */ `
mutation logout {
logout
}
`
export default logoutMutation