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 14, 2023
1 parent 6ec0a22 commit 90eac4e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ LANGUAGE_PREFERENCE_COOKIE_NAME=null
LMS_BASE_URL=null
LOGIN_URL=null
LOGOUT_URL=null
REDIRECT_ON_TPA_UNLINKED_ACCOUNT_URL=null
MARKETING_SITE_BASE_URL=null
ORDER_HISTORY_URL=null
REFRESH_ACCESS_TOKEN_ENDPOINT=null
Expand Down
5 changes: 5 additions & 0 deletions src/common-components/ThirdPartyAuthAlert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const ThirdPartyAuthAlert = (props) => {
const { formatMessage } = useIntl();
const { currentProvider, referrer } = props;
const platformName = getConfig().SITE_NAME;
const unlinkedRedirectUrl = getConfig().REDIRECT_ON_TPA_UNLINKED_ACCOUNT_URL;
let message;

if (referrer === LOGIN_PAGE) {
Expand All @@ -24,6 +25,10 @@ const ThirdPartyAuthAlert = (props) => {
return null;
}

if (unlinkedRedirectUrl) {
window.location.href = unlinkedRedirectUrl;
}

return (
<>
<Alert id="tpa-alert" className={referrer === REGISTER_PAGE ? 'alert-success mt-n2 mb-5' : 'alert-warning mt-n2 mb-5'}>
Expand Down
13 changes: 13 additions & 0 deletions src/common-components/tests/ThirdPartyAuthAlert.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';

import { mergeConfig } from '@edx/frontend-platform';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import renderer from 'react-test-renderer';

Expand Down Expand Up @@ -38,4 +39,16 @@ describe('ThirdPartyAuthAlert', () => {
).toJSON();
expect(tree).toMatchSnapshot();
});

it('should redirect on unlinked account', () => {
mergeConfig({
REDIRECT_ON_TPA_UNLINKED_ACCOUNT_URL: 'http://example.com',
});
renderer.create(
<IntlProvider locale="en">
<ThirdPartyAuthAlert {...props} />
</IntlProvider>,
);
expect(window.location.href).toEqual('http://example.com/');
});
});
1 change: 1 addition & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const configuration = {
SEARCH_CATALOG_URL: process.env.SEARCH_CATALOG_URL || null,
TOS_AND_HONOR_CODE: process.env.TOS_AND_HONOR_CODE || null,
TOS_LINK: process.env.TOS_LINK || null,
REDIRECT_ON_TPA_UNLINKED_ACCOUNT_URL: process.env.REDIRECT_ON_TPA_UNLINKED_ACCOUNT_URL || null,
// Base container images
BANNER_IMAGE_LARGE: process.env.BANNER_IMAGE_LARGE || '',
BANNER_IMAGE_MEDIUM: process.env.BANNER_IMAGE_MEDIUM || '',
Expand Down

0 comments on commit 90eac4e

Please sign in to comment.