From 3d6a05a9db89beef5e40ea0fdb5bd565d6ffba23 Mon Sep 17 00:00:00 2001 From: John Boxall Date: Fri, 29 Jul 2022 12:34:47 -0700 Subject: [PATCH 1/2] Remove references to session bridging This is unneeded with `plugin_slas`. --- .../app/commerce-api/auth.js | 30 ------------------- .../app/commerce-api/index.test.js | 3 -- 2 files changed, 33 deletions(-) diff --git a/packages/template-retail-react-app/app/commerce-api/auth.js b/packages/template-retail-react-app/app/commerce-api/auth.js index 74c6f8431e..d4af35649d 100644 --- a/packages/template-retail-react-app/app/commerce-api/auth.js +++ b/packages/template-retail-react-app/app/commerce-api/auth.js @@ -189,31 +189,6 @@ class Auth { return response } - /** - * Make a post request to the OCAPI /session endpoint to bridge the session. - * - * The HTTP response contains a set-cookie header which sets the dwsid session cookie. - * This cookie is used on SFRA site and it shoppers to navigate between SFRA site and - * this PWA site seamlessly, this is often used to enable hybrid deployment. - * - * (Note: this method is client side only, b/c MRT doesn't support set-cookie header right now) - * - * @returns {Promise} - */ - createOCAPISession() { - return fetch( - `${getAppOrigin()}/mobify/proxy/ocapi/s/${ - this._config.parameters.siteId - }/dw/shop/v21_3/sessions`, - { - method: 'POST', - headers: { - Authorization: this.authToken - } - } - ) - } - /** * Authorizes the customer as a registered or guest user. * @param {CustomerCredentials} [credentials] @@ -245,11 +220,6 @@ class Auth { } throw error }) - .then((result) => { - // Uncomment the following line for phased launch - // this._onClient && this.createOCAPISession() - return result - }) } this._pendingLogin = startLoginFlow().finally(() => { diff --git a/packages/template-retail-react-app/app/commerce-api/index.test.js b/packages/template-retail-react-app/app/commerce-api/index.test.js index f4d0667688..d53e998d63 100644 --- a/packages/template-retail-react-app/app/commerce-api/index.test.js +++ b/packages/template-retail-react-app/app/commerce-api/index.test.js @@ -24,7 +24,6 @@ import { ocapiBasketResponse, ocapiFaultResponse } from './mock-data' -import Auth from './auth' jest.mock('cross-fetch', () => jest.requireActual('jest-fetch-mock')) @@ -102,8 +101,6 @@ jest.mock('commerce-sdk-isomorphic', () => { } }) -jest.spyOn(Auth.prototype, 'createOCAPISession').mockImplementation(() => jest.fn()) - beforeEach(() => { jest.resetModules() // Clearing out mocked local storage before each test so tokens don't get mixed From 0f17746aba00e220be9026c1e88f11468ebf49f4 Mon Sep 17 00:00:00 2001 From: Alex Vuong Date: Wed, 3 Aug 2022 15:22:46 -0700 Subject: [PATCH 2/2] linting --- .../app/commerce-api/auth.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/template-retail-react-app/app/commerce-api/auth.js b/packages/template-retail-react-app/app/commerce-api/auth.js index d4af35649d..0e8a8a873a 100644 --- a/packages/template-retail-react-app/app/commerce-api/auth.js +++ b/packages/template-retail-react-app/app/commerce-api/auth.js @@ -210,16 +210,15 @@ class Auth { } else if (this.refreshToken) { authorizationMethod = '_refreshAccessToken' } - return this[authorizationMethod](credentials) - .catch((error) => { - const retryErrors = [INVALID_TOKEN, EXPIRED_TOKEN] - if (retries === 0 && retryErrors.includes(error.message)) { - retries = 1 // we only retry once - this._clearAuth() - return startLoginFlow() - } - throw error - }) + return this[authorizationMethod](credentials).catch((error) => { + const retryErrors = [INVALID_TOKEN, EXPIRED_TOKEN] + if (retries === 0 && retryErrors.includes(error.message)) { + retries = 1 // we only retry once + this._clearAuth() + return startLoginFlow() + } + throw error + }) } this._pendingLogin = startLoginFlow().finally(() => {