diff --git a/src/containers/App/Content.tsx b/src/containers/App/Content.tsx index 28fb22e28b..315e8b59b6 100644 --- a/src/containers/App/Content.tsx +++ b/src/containers/App/Content.tsx @@ -295,7 +295,7 @@ function ContentWrapper(props: ContentWrapperProps) { return ( - {!authUnavailable && ( + {!authUnavailable && !metaAuthUnavailable && ( diff --git a/src/containers/Authentication/Authentication.tsx b/src/containers/Authentication/Authentication.tsx index 21c5bd8680..149d355685 100644 --- a/src/containers/Authentication/Authentication.tsx +++ b/src/containers/Authentication/Authentication.tsx @@ -28,12 +28,27 @@ function Authentication({closable = false}: AuthenticationProps) { const needDatabase = useLoginWithDatabase(); - const useMeta = useMetaAuth(); - const [authenticate, {isLoading}] = authenticationApi.useAuthenticateMutation(); const {returnUrl, database: databaseFromQuery} = parseQuery(location); + const path = React.useMemo(() => { + let path: string | undefined; + + if (returnUrl) { + const decodedUrl = decodeURIComponent(returnUrl.toString()); + + // to prevent page reload we use router history + // history navigates relative to origin + // so we remove origin to make it work properly + const url = new URL(decodedUrl); + path = url.pathname + url.search; + } + return path; + }, [returnUrl]); + + const useMeta = useMetaAuth(path); + const [login, setLogin] = React.useState(''); const [database, setDatabase] = React.useState(databaseFromQuery?.toString() ?? ''); const [password, setPass] = React.useState(''); @@ -60,14 +75,7 @@ function Authentication({closable = false}: AuthenticationProps) { authenticate({user: login, password, database, useMeta}) .unwrap() .then(() => { - if (returnUrl) { - const decodedUrl = decodeURIComponent(returnUrl.toString()); - - // to prevent page reload we use router history - // history navigates relative to origin - // so we remove origin to make it work properly - const url = new URL(decodedUrl); - const path = url.pathname + url.search; + if (path) { history.replace(path); } }) diff --git a/src/utils/hooks/useMetaAuth.ts b/src/utils/hooks/useMetaAuth.ts index 22162565e4..eecf3a0233 100644 --- a/src/utils/hooks/useMetaAuth.ts +++ b/src/utils/hooks/useMetaAuth.ts @@ -6,23 +6,25 @@ import { useMetaWhoAmIAvailable, } from '../../store/reducers/capabilities/hooks'; -function useMetaAuthState() { +function useMetaAuthState(path?: string) { const location = useLocation(); - const isClustersPage = checkIsClustersPage(location.pathname); + const isClustersPage = path + ? checkIsClustersPage(path) + : checkIsClustersPage(location.pathname); const metaLoginAvailable = useMetaLoginAvailable(); const metaWhoAmIAvailable = useMetaWhoAmIAvailable(); return {isClustersPage, metaAuthAvailable: metaLoginAvailable && metaWhoAmIAvailable}; } -export function useMetaAuth() { - const {isClustersPage, metaAuthAvailable} = useMetaAuthState(); +export function useMetaAuth(path?: string) { + const {isClustersPage, metaAuthAvailable} = useMetaAuthState(path); return isClustersPage && metaAuthAvailable; } -export function useMetaAuthUnavailable() { - const {isClustersPage, metaAuthAvailable} = useMetaAuthState(); +export function useMetaAuthUnavailable(path?: string) { + const {isClustersPage, metaAuthAvailable} = useMetaAuthState(path); return isClustersPage && !metaAuthAvailable; }