Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/containers/App/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function ContentWrapper(props: ContentWrapperProps) {

return (
<Switch>
{!authUnavailable && (
{!authUnavailable && !metaAuthUnavailable && (
<Route path={routes.auth}>
<Authentication closable />
</Route>
Expand Down
28 changes: 18 additions & 10 deletions src/containers/Authentication/Authentication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand All @@ -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);
}
})
Expand Down
14 changes: 8 additions & 6 deletions src/utils/hooks/useMetaAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading