Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove references to session bridging #684

Merged
merged 4 commits into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 9 additions & 40 deletions packages/template-retail-react-app/app/commerce-api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -235,21 +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
})
.then((result) => {
// Uncomment the following line for phased launch
// this._onClient && this.createOCAPISession()
return result
})
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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
ocapiBasketResponse,
ocapiFaultResponse
} from './mock-data'
import Auth from './auth'

jest.mock('cross-fetch', () => jest.requireActual('jest-fetch-mock'))

Expand Down Expand Up @@ -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
Expand Down