Fixes SSO Redirect

This commit is contained in:
Alex Corey
2021-04-19 09:48:30 -04:00
parent 4cd4845617
commit c64fec0d98
2 changed files with 24 additions and 4 deletions

View File

@@ -42,12 +42,18 @@ function AWXLogin({ alt, i18n, isAuthenticated }) {
isLoading: isCustomLoginInfoLoading, isLoading: isCustomLoginInfoLoading,
error: customLoginInfoError, error: customLoginInfoError,
request: fetchCustomLoginInfo, request: fetchCustomLoginInfo,
result: { brandName, logo, loginInfo, socialAuthOptions }, result: {
brandName,
logo,
loginInfo,
socialAuthOptions,
loginRedirectOverride,
},
} = useRequest( } = useRequest(
useCallback(async () => { useCallback(async () => {
const [ const [
{ {
data: { custom_logo, custom_login_info }, data: { custom_logo, custom_login_info, login_redirect_override },
}, },
{ {
data: { BRAND_NAME }, data: { BRAND_NAME },
@@ -61,11 +67,13 @@ function AWXLogin({ alt, i18n, isAuthenticated }) {
const logoSrc = custom_logo const logoSrc = custom_logo
? `data:image/jpeg;${custom_logo}` ? `data:image/jpeg;${custom_logo}`
: loginLogoSrc; : loginLogoSrc;
return { return {
brandName: BRAND_NAME, brandName: BRAND_NAME,
logo: logoSrc, logo: logoSrc,
loginInfo: custom_login_info, loginInfo: custom_login_info,
socialAuthOptions: authData, socialAuthOptions: authData,
loginRedirectOverride: login_redirect_override,
}; };
}, []), }, []),
{ {
@@ -84,7 +92,6 @@ function AWXLogin({ alt, i18n, isAuthenticated }) {
useEffect(() => { useEffect(() => {
fetchCustomLoginInfo(); fetchCustomLoginInfo();
}, [fetchCustomLoginInfo]); }, [fetchCustomLoginInfo]);
const { const {
isLoading: isAuthenticating, isLoading: isAuthenticating,
error: authenticationError, error: authenticationError,
@@ -108,7 +115,10 @@ function AWXLogin({ alt, i18n, isAuthenticated }) {
if (isCustomLoginInfoLoading) { if (isCustomLoginInfoLoading) {
return null; return null;
} }
if (!isAuthenticated(document.cookie) && loginRedirectOverride) {
window.location.replace(loginRedirectOverride);
return null;
}
if (isAuthenticated(document.cookie)) { if (isAuthenticated(document.cookie)) {
return <Redirect to="/" />; return <Redirect to="/" />;
} }

View File

@@ -10,6 +10,16 @@ import AWXLogin from './Login';
jest.mock('../../api'); jest.mock('../../api');
RootAPI.readAssetVariables.mockResolvedValue({
data: {
BRAND_NAME: 'AWX',
},
});
AuthAPI.read.mockResolvedValue({
data: {},
});
describe('<Login />', () => { describe('<Login />', () => {
async function findChildren(wrapper) { async function findChildren(wrapper) {
const [ const [