Skip to content

Commit 7157570

Browse files
committed
fix: use meta if returnUrl is clusters page
1 parent e84ce6b commit 7157570

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/containers/Authentication/Authentication.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,27 @@ function Authentication({closable = false}: AuthenticationProps) {
2828

2929
const needDatabase = useLoginWithDatabase();
3030

31-
const useMeta = useMetaAuth();
32-
3331
const [authenticate, {isLoading}] = authenticationApi.useAuthenticateMutation();
3432

3533
const {returnUrl, database: databaseFromQuery} = parseQuery(location);
3634

35+
const path = React.useMemo(() => {
36+
let path: string | undefined;
37+
38+
if (returnUrl) {
39+
const decodedUrl = decodeURIComponent(returnUrl.toString());
40+
41+
// to prevent page reload we use router history
42+
// history navigates relative to origin
43+
// so we remove origin to make it work properly
44+
const url = new URL(decodedUrl);
45+
path = url.pathname + url.search;
46+
}
47+
return path;
48+
}, [returnUrl]);
49+
50+
const useMeta = useMetaAuth(path);
51+
3752
const [login, setLogin] = React.useState('');
3853
const [database, setDatabase] = React.useState(databaseFromQuery?.toString() ?? '');
3954
const [password, setPass] = React.useState('');
@@ -60,14 +75,7 @@ function Authentication({closable = false}: AuthenticationProps) {
6075
authenticate({user: login, password, database, useMeta})
6176
.unwrap()
6277
.then(() => {
63-
if (returnUrl) {
64-
const decodedUrl = decodeURIComponent(returnUrl.toString());
65-
66-
// to prevent page reload we use router history
67-
// history navigates relative to origin
68-
// so we remove origin to make it work properly
69-
const url = new URL(decodedUrl);
70-
const path = url.pathname + url.search;
78+
if (path) {
7179
history.replace(path);
7280
}
7381
})

src/utils/hooks/useMetaAuth.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ import {
66
useMetaWhoAmIAvailable,
77
} from '../../store/reducers/capabilities/hooks';
88

9-
function useMetaAuthState() {
9+
function useMetaAuthState(path = '') {
1010
const location = useLocation();
11-
const isClustersPage = checkIsClustersPage(location.pathname);
11+
const isClustersPage = checkIsClustersPage(location.pathname) || checkIsClustersPage(path);
1212
const metaLoginAvailable = useMetaLoginAvailable();
1313
const metaWhoAmIAvailable = useMetaWhoAmIAvailable();
1414

1515
return {isClustersPage, metaAuthAvailable: metaLoginAvailable && metaWhoAmIAvailable};
1616
}
1717

18-
export function useMetaAuth() {
19-
const {isClustersPage, metaAuthAvailable} = useMetaAuthState();
18+
export function useMetaAuth(path?: string) {
19+
const {isClustersPage, metaAuthAvailable} = useMetaAuthState(path);
2020

2121
return isClustersPage && metaAuthAvailable;
2222
}
2323

24-
export function useMetaAuthUnavailable() {
25-
const {isClustersPage, metaAuthAvailable} = useMetaAuthState();
24+
export function useMetaAuthUnavailable(path?: string) {
25+
const {isClustersPage, metaAuthAvailable} = useMetaAuthState(path);
2626

2727
return isClustersPage && !metaAuthAvailable;
2828
}

0 commit comments

Comments
 (0)