Skip to content

Commit 1acae39

Browse files
committed
feat: redirect to custom URL when third-party auth account is unlinked
1 parent 6ec0a22 commit 1acae39

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ LANGUAGE_PREFERENCE_COOKIE_NAME=null
88
LMS_BASE_URL=null
99
LOGIN_URL=null
1010
LOGOUT_URL=null
11+
REDIRECT_ON_TPA_UNLINKED_ACCOUNT_URL=null
1112
MARKETING_SITE_BASE_URL=null
1213
ORDER_HISTORY_URL=null
1314
REFRESH_ACCESS_TOKEN_ENDPOINT=null

src/common-components/ThirdPartyAuthAlert.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const ThirdPartyAuthAlert = (props) => {
1212
const { formatMessage } = useIntl();
1313
const { currentProvider, referrer } = props;
1414
const platformName = getConfig().SITE_NAME;
15+
const unlinkedRedirectUrl = getConfig().REDIRECT_ON_TPA_UNLINKED_ACCOUNT_URL;
1516
let message;
1617

1718
if (referrer === LOGIN_PAGE) {
@@ -24,6 +25,11 @@ const ThirdPartyAuthAlert = (props) => {
2425
return null;
2526
}
2627

28+
if (unlinkedRedirectUrl) {
29+
window.location.href = unlinkedRedirectUrl;
30+
return null;
31+
}
32+
2733
return (
2834
<>
2935
<Alert id="tpa-alert" className={referrer === REGISTER_PAGE ? 'alert-success mt-n2 mb-5' : 'alert-warning mt-n2 mb-5'}>

src/common-components/tests/ThirdPartyAuthAlert.test.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22

3+
import { mergeConfig } from '@edx/frontend-platform';
34
import { IntlProvider } from '@edx/frontend-platform/i18n';
45
import renderer from 'react-test-renderer';
56

@@ -38,4 +39,16 @@ describe('ThirdPartyAuthAlert', () => {
3839
).toJSON();
3940
expect(tree).toMatchSnapshot();
4041
});
42+
43+
it('should redirect on unlinked account', () => {
44+
mergeConfig({
45+
REDIRECT_ON_TPA_UNLINKED_ACCOUNT_URL: 'http://example.com',
46+
});
47+
renderer.create(
48+
<IntlProvider locale="en">
49+
<ThirdPartyAuthAlert {...props} />
50+
</IntlProvider>,
51+
);
52+
expect(window.location.href).toEqual('http://example.com/');
53+
});
4154
});

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
SEARCH_CATALOG_URL: process.env.SEARCH_CATALOG_URL || null,
2020
TOS_AND_HONOR_CODE: process.env.TOS_AND_HONOR_CODE || null,
2121
TOS_LINK: process.env.TOS_LINK || null,
22+
REDIRECT_ON_TPA_UNLINKED_ACCOUNT_URL: process.env.REDIRECT_ON_TPA_UNLINKED_ACCOUNT_URL || null,
2223
// Base container images
2324
BANNER_IMAGE_LARGE: process.env.BANNER_IMAGE_LARGE || '',
2425
BANNER_IMAGE_MEDIUM: process.env.BANNER_IMAGE_MEDIUM || '',

0 commit comments

Comments
 (0)