Fix UI errors after #3738 (#3787)

This commit is contained in:
Vivek Ratnavel Subramanian 2022-03-31 11:27:51 -07:00 committed by GitHub
parent c50f71b478
commit aa81ceab1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 59 deletions

View File

@ -30,14 +30,12 @@ import React, {
} from 'react'; } from 'react';
import { useHistory, useLocation } from 'react-router-dom'; import { useHistory, useLocation } from 'react-router-dom';
import appState from '../AppState'; import appState from '../AppState';
// import GoogleAuthenticator from '../authenticators/GoogleAuthenticator';
import MsalAuthenticator from '../authenticators/MsalAuthenticator'; import MsalAuthenticator from '../authenticators/MsalAuthenticator';
import OidcAuthenticator from '../authenticators/OidcAuthenticator'; import OidcAuthenticator from '../authenticators/OidcAuthenticator';
import OktaAuthenticator from '../authenticators/OktaAuthenticator'; import OktaAuthenticator from '../authenticators/OktaAuthenticator';
import axiosClient from '../axiosAPIs'; import axiosClient from '../axiosAPIs';
import { import {
fetchAuthenticationConfig, fetchAuthenticationConfig,
fetchAuthorizerConfig,
getLoggedInUserPermissions, getLoggedInUserPermissions,
} from '../axiosAPIs/miscAPI'; } from '../axiosAPIs/miscAPI';
import { import {
@ -46,7 +44,7 @@ import {
updateUser, updateUser,
} from '../axiosAPIs/userAPI'; } from '../axiosAPIs/userAPI';
import Loader from '../components/Loader/Loader'; import Loader from '../components/Loader/Loader';
import { NOOP_FILTER, NO_AUTH } from '../constants/auth.constants'; import { NO_AUTH } from '../constants/auth.constants';
import { isAdminUpdated, oidcTokenKey, ROUTES } from '../constants/constants'; import { isAdminUpdated, oidcTokenKey, ROUTES } from '../constants/constants';
import { ClientErrors } from '../enums/axios.enum'; import { ClientErrors } from '../enums/axios.enum';
import { AuthTypes } from '../enums/signin.enum'; import { AuthTypes } from '../enums/signin.enum';
@ -250,30 +248,12 @@ export const AuthProvider = ({
}; };
const fetchAuthConfig = (): void => { const fetchAuthConfig = (): void => {
const promises = [fetchAuthenticationConfig(), fetchAuthorizerConfig()]; fetchAuthenticationConfig()
Promise.allSettled(promises) .then((authRes: AxiosResponse) => {
.then(
([
authenticationConfig,
authorizerConfig,
]: PromiseSettledResult<AxiosResponse>[]) => {
let authRes = {} as AxiosResponse;
if (authenticationConfig.status === 'fulfilled') {
authRes = authenticationConfig.value;
const authorizerRes =
authorizerConfig.status === 'fulfilled'
? authorizerConfig.value
: ({} as AxiosResponse);
const isSecureMode = const isSecureMode =
!isNil(authRes.data) && !isNil(authRes.data) && authRes.data.provider !== NO_AUTH;
authorizerRes?.data?.containerRequestFilter &&
authRes.data.provider !== NO_AUTH &&
authorizerRes.data.containerRequestFilter !== NOOP_FILTER &&
Object.values(authRes.data).filter((item) => isNil(item))
.length === 0;
if (isSecureMode) { if (isSecureMode) {
const { provider, authority, clientId, callbackUrl } = const { provider, authority, clientId, callbackUrl } = authRes.data;
authRes.data;
const configJson = getAuthConfig({ const configJson = getAuthConfig({
authority, authority,
clientId, clientId,
@ -292,21 +272,11 @@ export const AuthProvider = ({
setIsAuthDisabled(true); setIsAuthDisabled(true);
fetchAllUsers(); fetchAllUsers();
} }
} else { })
authenticationConfig.reason as AxiosError; .catch((err: AxiosError) => {
showToast({ showToast({
variant: 'error', variant: 'error',
body: body: `Error occurred while fetching auth config: ${err.message}`,
(authenticationConfig.reason as AxiosError).response?.data
.message || 'Error occured while fetching auth config',
});
}
}
)
.catch(() => {
showToast({
variant: 'error',
body: 'Error occured while fetching auth config',
}); });
}); });
}; };

View File

@ -55,10 +55,6 @@ export const fetchAuthenticationConfig: Function =
return APIClient.get('/config/auth'); return APIClient.get('/config/auth');
}; };
export const fetchAuthorizerConfig: Function = (): Promise<AxiosResponse> => {
return APIClient.get('/config/authorizer');
};
export const fetchSandboxConfig = (): Promise<AxiosResponse> => { export const fetchSandboxConfig = (): Promise<AxiosResponse> => {
return APIClient.get('/config/sandbox'); return APIClient.get('/config/sandbox');
}; };