Skip to content

Commit 06687b9

Browse files
committed
feat: redirect to custom URL when third-party auth account is unlinked
1 parent ef66eb1 commit 06687b9

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ORDER_HISTORY_URL=null
1313
REFRESH_ACCESS_TOKEN_ENDPOINT=null
1414
SEGMENT_KEY=''
1515
SITE_NAME=null
16+
TPA_UNLINKED_ACCOUNT_PROVISION_URL=null
1617
INFO_EMAIL=''
1718
# ***** Cookies *****
1819
REGISTER_CONVERSION_COOKIE_NAME=null

src/config/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const configuration = {
1919
PRIVACY_POLICY: process.env.PRIVACY_POLICY || null,
2020
TOS_AND_HONOR_CODE: process.env.TOS_AND_HONOR_CODE || null,
2121
TOS_LINK: process.env.TOS_LINK || null,
22+
TPA_UNLINKED_ACCOUNT_PROVISION_URL: process.env.TPA_UNLINKED_ACCOUNT_PROVISION_URL || null,
2223
// Miscellaneous
2324
GENERAL_RECOMMENDATIONS: process.env.GENERAL_RECOMMENDATIONS || '[]',
2425
INFO_EMAIL: process.env.INFO_EMAIL || '',

src/login/LoginPage.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,18 @@ class LoginPage extends React.Component {
321321
} = this.props;
322322
const { currentProvider, providers, secondaryProviders } = this.props.thirdPartyAuthContext;
323323

324+
const unlinkedProvisionUrl = getConfig().TPA_UNLINKED_ACCOUNT_PROVISION_URL;
325+
326+
/**
327+
* When currentProvider exists and we are in a login page, it is
328+
* because the third-party authenticated account is not linked.
329+
* See also ThirdPartyAuthAlert.jsx.
330+
*/
331+
if (currentProvider && unlinkedProvisionUrl) {
332+
window.location.href = unlinkedProvisionUrl;
333+
return null;
334+
}
335+
324336
if (this.tpaHint) {
325337
if (thirdPartyAuthApiStatus === PENDING_STATE) {
326338
return <Skeleton height={36} />;

src/login/tests/LoginPage.test.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,4 +791,24 @@ describe('LoginPage', () => {
791791

792792
expect(store.dispatch).toHaveBeenCalledWith(loginRemovePasswordResetBanner());
793793
});
794+
795+
it('should redirect to provisioning URL on unlinked third-party auth account', () => {
796+
mergeConfig({
797+
TPA_UNLINKED_ACCOUNT_PROVISION_URL: 'http://example.com',
798+
});
799+
800+
store = mockStore({
801+
...initialState,
802+
commonComponents: {
803+
...initialState.commonComponents,
804+
thirdPartyAuthContext: {
805+
...initialState.commonComponents.thirdPartyAuthContext,
806+
currentProvider: ssoProvider.name,
807+
},
808+
},
809+
});
810+
811+
const loginPage = mount(reduxWrapper(<IntlLoginPage {...props} />));
812+
expect(window.location.href).toEqual('http://example.com');
813+
});
794814
});

0 commit comments

Comments
 (0)