From 12a96103a880f49fe4040abe4a05f7fbb79fd3c2 Mon Sep 17 00:00:00 2001 From: Loan Laux Date: Fri, 23 Apr 2021 20:56:55 +0400 Subject: [PATCH] add logout Signed-off-by: Loan Laux --- framework/reactioncommerce/auth/use-logout.tsx | 7 ++----- framework/reactioncommerce/fetcher.ts | 2 +- .../mutations/customer-access-token-delete.ts | 14 -------------- .../reactioncommerce/utils/mutations/index.ts | 2 +- .../reactioncommerce/utils/mutations/logout.ts | 7 +++++++ 5 files changed, 11 insertions(+), 21 deletions(-) delete mode 100644 framework/reactioncommerce/utils/mutations/customer-access-token-delete.ts create mode 100644 framework/reactioncommerce/utils/mutations/logout.ts diff --git a/framework/reactioncommerce/auth/use-logout.tsx b/framework/reactioncommerce/auth/use-logout.tsx index 81a3b8cdd..a4ea1d3d0 100644 --- a/framework/reactioncommerce/auth/use-logout.tsx +++ b/framework/reactioncommerce/auth/use-logout.tsx @@ -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 export const handler: MutationHook = { fetchOptions: { - query: customerAccessTokenDeleteMutation, + query: logoutMutation, }, async fetcher({ options, fetch }) { await fetch({ ...options, - variables: { - customerAccessToken: getCustomerToken(), - }, }) setCustomerToken(null) return null diff --git a/framework/reactioncommerce/fetcher.ts b/framework/reactioncommerce/fetcher.ts index 4b774d081..0ea43543d 100644 --- a/framework/reactioncommerce/fetcher.ts +++ b/framework/reactioncommerce/fetcher.ts @@ -33,7 +33,7 @@ const fetcher: Fetcher = async ({ const authorizationHeader = {} if (customerToken) { - authorizationHeader['Authorization'] = `bearer ${customerToken}` + authorizationHeader['Authorization'] = `Bearer ${customerToken}` } return handleFetchResponse( diff --git a/framework/reactioncommerce/utils/mutations/customer-access-token-delete.ts b/framework/reactioncommerce/utils/mutations/customer-access-token-delete.ts deleted file mode 100644 index c46eff1e5..000000000 --- a/framework/reactioncommerce/utils/mutations/customer-access-token-delete.ts +++ /dev/null @@ -1,14 +0,0 @@ -const customerAccessTokenDeleteMutation = /* GraphQL */ ` - mutation customerAccessTokenDelete($customerAccessToken: String!) { - customerAccessTokenDelete(customerAccessToken: $customerAccessToken) { - deletedAccessToken - deletedCustomerAccessTokenId - userErrors { - field - message - } - } - } -` - -export default customerAccessTokenDeleteMutation diff --git a/framework/reactioncommerce/utils/mutations/index.ts b/framework/reactioncommerce/utils/mutations/index.ts index fe4bcf04f..e8b6c7fb1 100644 --- a/framework/reactioncommerce/utils/mutations/index.ts +++ b/framework/reactioncommerce/utils/mutations/index.ts @@ -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' diff --git a/framework/reactioncommerce/utils/mutations/logout.ts b/framework/reactioncommerce/utils/mutations/logout.ts new file mode 100644 index 000000000..bbc289f26 --- /dev/null +++ b/framework/reactioncommerce/utils/mutations/logout.ts @@ -0,0 +1,7 @@ +const logoutMutation = /* GraphQL */ ` + mutation logout { + logout + } +` + +export default logoutMutation