@@ -2,22 +2,23 @@ import React from 'react';
22
33import { connect } from 'react-redux' ;
44import type { RedirectProps } from 'react-router-dom' ;
5- import { Redirect , Route , Switch } from 'react-router-dom' ;
5+ import { Redirect , Route , Switch , useLocation } from 'react-router-dom' ;
66
77import { AccessDenied } from '../../components/Errors/403' ;
88import { PageError } from '../../components/Errors/PageError/PageError' ;
99import { LoaderWrapper } from '../../components/LoaderWrapper/LoaderWrapper' ;
1010import { useSlots } from '../../components/slots' ;
1111import type { SlotMap } from '../../components/slots/SlotMap' ;
1212import type { SlotComponent } from '../../components/slots/types' ;
13- import routes from '../../routes' ;
13+ import routes , { checkIsClustersPage } from '../../routes' ;
1414import type { RootState } from '../../store' ;
1515import { authenticationApi } from '../../store/reducers/authentication/authentication' ;
1616import {
1717 useCapabilitiesQuery ,
1818 useClusterWithoutAuthInUI ,
1919 useMetaCapabilitiesLoaded ,
2020 useMetaCapabilitiesQuery ,
21+ useMetaLoginAvailable ,
2122} from '../../store/reducers/capabilities/hooks' ;
2223import { nodesListApi } from '../../store/reducers/nodesList' ;
2324import { uiFactory } from '../../uiFactory/uiFactory' ;
@@ -160,7 +161,7 @@ export function Content(props: ContentProps) {
160161 exact : true ,
161162 component : Clusters ,
162163 slot : ClustersSlot ,
163- wrapper : GetMetaCapabilities ,
164+ wrapper : ClustersDataWrapper ,
164165 } ) }
165166 { /* Single cluster routes */ }
166167 { routesSlots . map ( ( route ) => {
@@ -191,9 +192,34 @@ function DataWrapper({children}: {children: React.ReactNode}) {
191192 ) ;
192193}
193194
194- function GetUser ( { children} : { children : React . ReactNode } ) {
195+ function ClustersDataWrapper ( { children} : { children : React . ReactNode } ) {
196+ return (
197+ < GetMetaCapabilities >
198+ < GetMetaUser > { children } </ GetMetaUser >
199+ </ GetMetaCapabilities >
200+ ) ;
201+ }
202+
203+ function GetMetaUser ( { children} : { children : React . ReactNode } ) {
204+ const location = useLocation ( ) ;
205+
206+ const isClustersPage = checkIsClustersPage ( location . pathname ) ;
207+
208+ const isMetaLoginAvailable = useMetaLoginAvailable ( ) ;
209+
210+ if ( isClustersPage && isMetaLoginAvailable ) {
211+ return < GetUser useMeta > { children } </ GetUser > ;
212+ }
213+ return children ;
214+ }
215+
216+ function GetUser ( { children, useMeta} : { children : React . ReactNode ; useMeta ?: boolean } ) {
195217 const database = useDatabaseFromQuery ( ) ;
196- const { isLoading, error} = authenticationApi . useWhoamiQuery ( { database} ) ;
218+
219+ const { isLoading, error} = authenticationApi . useWhoamiQuery ( {
220+ database,
221+ useMeta,
222+ } ) ;
197223 const { appTitle} = useAppTitle ( ) ;
198224
199225 const errorProps = error ? { ...uiFactory . clusterOrDatabaseAccessError } : undefined ;
@@ -262,8 +288,15 @@ function ContentWrapper(props: ContentWrapperProps) {
262288 const { singleClusterMode, isAuthenticated} = props ;
263289 const authUnavailable = useClusterWithoutAuthInUI ( ) ;
264290
291+ const location = useLocation ( ) ;
292+ const isClustersPage = checkIsClustersPage ( location . pathname ) ;
293+
294+ const isMetaLoginAvailable = useMetaLoginAvailable ( ) ;
295+
296+ const isClustersAuthUnavailable = isClustersPage && ! isMetaLoginAvailable ;
297+
265298 const renderNotAuthenticated = ( ) => {
266- if ( authUnavailable ) {
299+ if ( authUnavailable || isClustersAuthUnavailable ) {
267300 return < AccessDenied /> ;
268301 }
269302 return < Authentication /> ;
0 commit comments