diff --git a/src/data/utils/dataUtils.js b/src/data/utils/dataUtils.js
index 0963afa7..7170990b 100644
--- a/src/data/utils/dataUtils.js
+++ b/src/data/utils/dataUtils.js
@@ -29,11 +29,12 @@ export const getTpaProvider = (tpaHintProvider, primaryProviders, secondaryProvi
return tpaProvider;
};
-export const processTpaHintURL = (params) => {
+export const getTpaHint = () => {
+ const params = QueryString.parse(window.location.search);
let tpaHint = null;
- tpaHint = params.get('tpa_hint');
+ tpaHint = params.tpa_hint;
if (!tpaHint) {
- const next = params.get('next');
+ const { next } = params;
if (next) {
const index = next.indexOf('tpa_hint=');
if (index !== -1) {
@@ -55,7 +56,7 @@ export const updatePathWithQueryParams = (path) => {
};
export const getAllPossibleQueryParam = () => {
- const urlParams = QueryString.parse(document.location.search);
+ const urlParams = QueryString.parse(window.location.search);
const params = {};
Object.entries(urlParams).forEach(([key, value]) => {
if (AUTH_PARAMS.indexOf(key) > -1) {
@@ -65,3 +66,9 @@ export const getAllPossibleQueryParam = () => {
return params;
};
+
+export const getActivationStatus = () => {
+ const params = QueryString.parse(window.location.search);
+
+ return params.account_activation_status;
+};
diff --git a/src/data/utils/index.js b/src/data/utils/index.js
index 6719e5ef..261839a2 100644
--- a/src/data/utils/index.js
+++ b/src/data/utils/index.js
@@ -1,8 +1,9 @@
export {
default,
getTpaProvider,
- processTpaHintURL,
+ getTpaHint,
updatePathWithQueryParams,
getAllPossibleQueryParam,
+ getActivationStatus,
} from './dataUtils';
export { default as AsyncActionType } from './reduxUtils';
diff --git a/src/login/LoginPage.jsx b/src/login/LoginPage.jsx
index fbc44f0f..d1e2bc7d 100644
--- a/src/login/LoginPage.jsx
+++ b/src/login/LoginPage.jsx
@@ -29,11 +29,11 @@ import {
InstitutionLogistration, AuthnValidationFormGroup,
} from '../common-components';
import {
- DEFAULT_REDIRECT_URL, DEFAULT_STATE, LOGIN_PAGE, REGISTER_PAGE, ENTERPRISE_LOGIN_URL, PENDING_STATE,
+ DEFAULT_STATE, LOGIN_PAGE, REGISTER_PAGE, ENTERPRISE_LOGIN_URL, PENDING_STATE,
} from '../data/constants';
import { forgotPasswordResultSelector } from '../forgot-password';
import {
- getTpaProvider, processTpaHintURL, updatePathWithQueryParams, getAllPossibleQueryParam,
+ getTpaProvider, getTpaHint, updatePathWithQueryParams, getAllPossibleQueryParam, getActivationStatus,
} from '../data/utils';
class LoginPage extends React.Component {
@@ -51,17 +51,15 @@ class LoginPage extends React.Component {
institutionLogin: false,
isSubmitted: false,
};
+ this.queryParams = getAllPossibleQueryParam();
+ this.tpaHint = getTpaHint();
}
componentDidMount() {
- const params = (new URL(document.location)).searchParams;
- const payload = {
- redirect_to: params.get('next') || DEFAULT_REDIRECT_URL,
- };
+ const payload = { ...this.queryParams };
- const tpaHint = processTpaHintURL(params);
- if (tpaHint) {
- payload.tpa_hint = tpaHint;
+ if (this.tpaHint) {
+ payload.tpa_hint = this.tpaHint;
}
this.props.getThirdPartyAuthContext(payload);
}
@@ -92,10 +90,9 @@ class LoginPage extends React.Component {
return;
}
- let payload = { email, password };
- const postParams = getAllPossibleQueryParam();
-
- payload = { ...payload, ...postParams };
+ const payload = {
+ email, password, ...this.queryParams,
+ };
this.props.loginRequest(payload);
}
@@ -148,16 +145,17 @@ class LoginPage extends React.Component {
} return thirdPartyComponent;
}
- renderForm(params,
+ renderForm(
currentProvider,
providers,
secondaryProviders,
thirdPartyAuthContext,
thirdPartyAuthApiStatus,
submitState,
- intl) {
+ intl,
+ ) {
const { email, errors, password } = this.state;
- const activationMsgType = params.get('account_activation_status');
+ const activationMsgType = getActivationStatus();
if (this.state.institutionLogin) {
return (
;
}
- const provider = getTpaProvider(tpaHint, providers, secondaryProviders);
- return provider ? () : this.renderForm(params,
+ const provider = getTpaProvider(this.tpaHint, providers, secondaryProviders);
+ return provider ? () : this.renderForm(
currentProvider,
providers,
secondaryProviders,
thirdPartyAuthContext,
thirdPartyAuthApiStatus,
submitState,
- intl);
+ intl,
+ );
}
- return this.renderForm(params,
+ return this.renderForm(
currentProvider,
providers,
secondaryProviders,
thirdPartyAuthContext,
thirdPartyAuthApiStatus,
submitState,
- intl);
+ intl,
+ );
}
}
diff --git a/src/login/tests/LoginPage.test.jsx b/src/login/tests/LoginPage.test.jsx
index 7e7295d2..844a9bdc 100644
--- a/src/login/tests/LoginPage.test.jsx
+++ b/src/login/tests/LoginPage.test.jsx
@@ -133,7 +133,7 @@ describe('LoginPage', () => {
it('should show account activation message', () => {
delete window.location;
- window.location = { href: getConfig().BASE_URL.concat('/login?account_activation_status=info') };
+ window.location = { href: getConfig().BASE_URL.concat('/login'), search: '?account_activation_status=info' };
const expectedMessage = 'This account has already been activated.';
@@ -429,7 +429,7 @@ describe('LoginPage', () => {
});
delete window.location;
- window.location = { href: getConfig().BASE_URL.concat(`/login?next=/dashboard&tpa_hint=${appleProvider.id}`) };
+ window.location = { href: getConfig().BASE_URL.concat('/login'), search: `?next=/dashboard&tpa_hint=${appleProvider.id}` };
appleProvider.iconImage = null;
const loginPage = mount(reduxWrapper());
@@ -451,7 +451,7 @@ describe('LoginPage', () => {
});
delete window.location;
- window.location = { href: getConfig().BASE_URL.concat('/login?next=/dashboard&tpa_hint=invalid') };
+ window.location = { href: getConfig().BASE_URL.concat('/login'), search: '?next=/dashboard&tpa_hint=invalid' };
appleProvider.iconImage = null;
const loginPage = mount(reduxWrapper());
@@ -473,7 +473,7 @@ describe('LoginPage', () => {
});
delete window.location;
- window.location = { href: getConfig().BASE_URL.concat(`/login?next=/dashboard&tpa_hint=${secondaryProviders.id}`) };
+ window.location = { href: getConfig().BASE_URL.concat('/login'), search: `?next=/dashboard&tpa_hint=${secondaryProviders.id}` };
secondaryProviders.iconImage = null;
const loginPage = mount(reduxWrapper());
diff --git a/src/register/RegistrationPage.jsx b/src/register/RegistrationPage.jsx
index a7ffbac9..212deed2 100644
--- a/src/register/RegistrationPage.jsx
+++ b/src/register/RegistrationPage.jsx
@@ -29,10 +29,10 @@ import { getThirdPartyAuthContext } from '../common-components/data/actions';
import { thirdPartyAuthContextSelector } from '../common-components/data/selectors';
import EnterpriseSSO from '../common-components/EnterpriseSSO';
import {
- DEFAULT_REDIRECT_URL, DEFAULT_STATE, LOGIN_PAGE, PENDING_STATE, REGISTER_PAGE,
+ DEFAULT_STATE, LOGIN_PAGE, PENDING_STATE, REGISTER_PAGE,
} from '../data/constants';
import {
- getTpaProvider, processTpaHintURL, updatePathWithQueryParams, getAllPossibleQueryParam,
+ getTpaProvider, getTpaHint, updatePathWithQueryParams, getAllPossibleQueryParam,
} from '../data/utils';
class RegistrationPage extends React.Component {
@@ -41,6 +41,8 @@ class RegistrationPage extends React.Component {
sendPageEvent('login_and_registration', 'register');
this.intl = props.intl;
+ this.queryParams = getAllPossibleQueryParam();
+ this.tpaHint = getTpaHint();
this.state = {
email: '',
@@ -77,14 +79,10 @@ class RegistrationPage extends React.Component {
}
componentDidMount() {
- const params = (new URL(document.location)).searchParams;
- const payload = {
- redirect_to: params.get('next') || DEFAULT_REDIRECT_URL,
- };
+ const payload = { ...this.queryParams };
- const tpaHint = processTpaHintURL(params);
- if (tpaHint) {
- payload.tpa_hint = tpaHint;
+ if (this.tpaHint) {
+ payload.tpa_hint = this.tpaHint;
}
this.props.getThirdPartyAuthContext(payload);
}
@@ -624,14 +622,11 @@ class RegistrationPage extends React.Component {
currentProvider, finishAuthUrl, providers, secondaryProviders,
} = this.props.thirdPartyAuthContext;
- const params = (new URL(window.location.href)).searchParams;
- const tpaHint = processTpaHintURL(params);
-
- if (tpaHint) {
+ if (this.tpaHint) {
if (thirdPartyAuthApiStatus === PENDING_STATE) {
return ;
}
- const provider = getTpaProvider(tpaHint, providers, secondaryProviders);
+ const provider = getTpaProvider(this.tpaHint, providers, secondaryProviders);
return provider ? ()
: this.renderForm(
currentProvider,
diff --git a/src/register/tests/RegistrationPage.test.jsx b/src/register/tests/RegistrationPage.test.jsx
index 97bade65..64bb94a7 100644
--- a/src/register/tests/RegistrationPage.test.jsx
+++ b/src/register/tests/RegistrationPage.test.jsx
@@ -654,7 +654,7 @@ describe('RegistrationPageTests', () => {
});
delete window.location;
- window.location = { href: getConfig().BASE_URL.concat(`/login?next=/dashboard&tpa_hint=${appleProvider.id}`) };
+ window.location = { href: getConfig().BASE_URL.concat('/login'), search: `?next=/dashboard&tpa_hint=${appleProvider.id}` };
appleProvider.iconImage = null;
const registerPage = mount(reduxWrapper());
@@ -676,7 +676,7 @@ describe('RegistrationPageTests', () => {
});
delete window.location;
- window.location = { href: getConfig().BASE_URL.concat('/login?next=/dashboard&tpa_hint=invalid') };
+ window.location = { href: getConfig().BASE_URL.concat('/login'), search: '?next=/dashboard&tpa_hint=invalid' };
appleProvider.iconImage = null;
const registerPage = mount(reduxWrapper());
@@ -698,7 +698,7 @@ describe('RegistrationPageTests', () => {
});
delete window.location;
- window.location = { href: getConfig().BASE_URL.concat(`/login?next=/dashboard&tpa_hint=${secondaryProviders.id}`) };
+ window.location = { href: getConfig().BASE_URL.concat('/login'), search: `?next=/dashboard&tpa_hint=${secondaryProviders.id}` };
secondaryProviders.iconImage = null;
const registerPage = mount(reduxWrapper());