Skip to content

Commit

Permalink
feat: redirect to custom URL when third-party auth account is unlinked
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturGaspar committed Oct 25, 2023
1 parent ccbd87d commit 08563c3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Expand Up @@ -13,6 +13,7 @@ ORDER_HISTORY_URL=null
REFRESH_ACCESS_TOKEN_ENDPOINT=null
SEGMENT_KEY=''
SITE_NAME=null
TPA_UNLINKED_ACCOUNT_PROVISION_URL=null
INFO_EMAIL=''
# ***** Cookies *****
REGISTER_CONVERSION_COOKIE_NAME=null
Expand Down
1 change: 1 addition & 0 deletions src/config/index.js
Expand Up @@ -19,6 +19,7 @@ const configuration = {
PRIVACY_POLICY: process.env.PRIVACY_POLICY || null,
TOS_AND_HONOR_CODE: process.env.TOS_AND_HONOR_CODE || null,
TOS_LINK: process.env.TOS_LINK || null,
TPA_UNLINKED_ACCOUNT_PROVISION_URL: process.env.TPA_UNLINKED_ACCOUNT_PROVISION_URL || null,
// Miscellaneous
GENERAL_RECOMMENDATIONS: process.env.GENERAL_RECOMMENDATIONS || '[]',
INFO_EMAIL: process.env.INFO_EMAIL || '',
Expand Down
12 changes: 12 additions & 0 deletions src/login/LoginPage.jsx
Expand Up @@ -321,6 +321,18 @@ class LoginPage extends React.Component {
} = this.props;
const { currentProvider, providers, secondaryProviders } = this.props.thirdPartyAuthContext;

const unlinkedProvisionUrl = getConfig().TPA_UNLINKED_ACCOUNT_PROVISION_URL;

/**
* When currentProvider exists and we are in a login page, it is
* because the third-party authenticated account is not linked.
* See also ThirdPartyAuthAlert.jsx.
*/
if (currentProvider && unlinkedProvisionUrl) {
window.location.href = unlinkedProvisionUrl;
return null;
}

if (this.tpaHint) {
if (thirdPartyAuthApiStatus === PENDING_STATE) {
return <Skeleton height={36} />;
Expand Down
20 changes: 20 additions & 0 deletions src/login/tests/LoginPage.test.jsx
Expand Up @@ -791,4 +791,24 @@ describe('LoginPage', () => {

expect(store.dispatch).toHaveBeenCalledWith(loginRemovePasswordResetBanner());
});

it('should redirect to provisioning URL on unlinked third-party auth account', () => {
mergeConfig({
TPA_UNLINKED_ACCOUNT_PROVISION_URL: 'http://example.com',
});

store = mockStore({
...initialState,
commonComponents: {
...initialState.commonComponents,
thirdPartyAuthContext: {
...initialState.commonComponents.thirdPartyAuthContext,
currentProvider: ssoProvider.name,
},
},
});

const loginPage = mount(reduxWrapper(<IntlLoginPage {...props} />));

Check failure on line 811 in src/login/tests/LoginPage.test.jsx

View workflow job for this annotation

GitHub Actions / tests

'loginPage' is assigned a value but never used
expect(window.location.href).toEqual('http://example.com');
});
});

0 comments on commit 08563c3

Please sign in to comment.