@@ -19,14 +19,15 @@ import { CoreStart } from 'opensearch-dashboards/public';
1919import { AccountNavButton } from './account-nav-button' ;
2020import { fetchAccountInfoSafe } from './utils' ;
2121import { ClientConfigType } from '../../types' ;
22- import { CUSTOM_ERROR_PAGE_URI , ERROR_MISSING_ROLE_PATH } from '../../../common' ;
22+ import { AuthType , CUSTOM_ERROR_PAGE_URI , ERROR_MISSING_ROLE_PATH } from '../../../common' ;
2323import { fetchCurrentTenant , selectTenant } from '../configuration/utils/tenant-utils' ;
2424import {
2525 getSavedTenant ,
2626 getShouldShowTenantPopup ,
2727 setShouldShowTenantPopup ,
2828} from '../../utils/storage-utils' ;
2929import { constructErrorMessageAndLog } from '../error-utils' ;
30+ import { fetchCurrentAuthType } from '../../utils/logout-utils' ;
3031
3132function tenantSpecifiedInUrl ( ) {
3233 return (
@@ -36,6 +37,20 @@ function tenantSpecifiedInUrl() {
3637}
3738
3839export async function setupTopNavButton ( coreStart : CoreStart , config : ClientConfigType ) {
40+ const authType = config . auth ?. type ;
41+ let currAuthType = '' ;
42+ if ( typeof authType === 'string' ) {
43+ currAuthType = authType ;
44+ } else if ( Array . isArray ( authType ) && authType . length === 1 ) {
45+ currAuthType = authType [ 0 ] ;
46+ } else {
47+ try {
48+ currAuthType = ( await fetchCurrentAuthType ( coreStart . http ) ) ?. currentAuthType ;
49+ } catch ( e ) {
50+ currAuthType = AuthType . BASIC ;
51+ }
52+ }
53+
3954 const accountInfo = ( await fetchAccountInfoSafe ( coreStart . http ) ) ?. data ;
4055 if ( accountInfo ) {
4156 // Missing role error
@@ -94,6 +109,7 @@ export async function setupTopNavButton(coreStart: CoreStart, config: ClientConf
94109 username = { accountInfo . user_name }
95110 tenant = { tenant }
96111 config = { config }
112+ currAuthType = { currAuthType . toLowerCase ( ) }
97113 /> ,
98114 element
99115 ) ;
0 commit comments