Skip to content

Commit f4551cd

Browse files
authored
Merge pull request #4402 from mudit06mah/deeplinkRoute
Frontend: Router: Unauthenticated users can now follow deeplinks.
2 parents 6061941 + ace8cec commit f4551cd

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

frontend/src/components/App/RouteSwitcher.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function AuthRoute(props: AuthRouteProps) {
162162
computedMatch = {},
163163
...other
164164
} = props;
165-
const redirectRoute = getCluster() ? 'login' : 'chooser';
165+
166166
useSidebarItem(sidebar, computedMatch);
167167
const cluster = useCluster();
168168
const query = useQuery({
@@ -172,6 +172,24 @@ function AuthRoute(props: AuthRouteProps) {
172172
retry: 0,
173173
});
174174

175+
const clusters = useClustersConf();
176+
const currentCluster = getCluster();
177+
const clusterConf = currentCluster && clusters ? clusters[currentCluster] : null;
178+
const authError = query.error as any;
179+
const isExplicitAuthError = [401, 403].includes(authError?.status);
180+
181+
let redirectRoute: string;
182+
183+
if (!currentCluster) {
184+
redirectRoute = 'chooser';
185+
} else if (clusterConf?.auth_type === 'oidc') {
186+
redirectRoute = 'login';
187+
} else if (query.isError && isExplicitAuthError) {
188+
redirectRoute = 'token';
189+
} else {
190+
redirectRoute = 'login';
191+
}
192+
175193
function getRenderer({ location }: RouteProps) {
176194
if (!requiresAuth) {
177195
return children;

frontend/src/components/account/Auth.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import TextField from '@mui/material/TextField';
2525
import Typography from '@mui/material/Typography';
2626
import React from 'react';
2727
import { Trans, useTranslation } from 'react-i18next';
28-
import { generatePath, useHistory } from 'react-router-dom';
28+
import { generatePath, useHistory, useLocation } from 'react-router-dom';
2929
import { setToken } from '../../lib/auth';
3030
import { getCluster, getClusterPrefixedPath } from '../../lib/cluster';
3131
import { useClustersConf } from '../../lib/k8s';
@@ -37,6 +37,7 @@ import HeadlampLink from '../common/Link';
3737

3838
export default function AuthToken() {
3939
const history = useHistory();
40+
const location = useLocation<{ from?: Location }>();
4041
const clusterConf = useClustersConf();
4142
const [token, setToken] = React.useState('');
4243
const [showError, setShowError] = React.useState(false);
@@ -47,11 +48,15 @@ export default function AuthToken() {
4748
loginWithToken(token).then(code => {
4849
// If successful, redirect.
4950
if (code === 200) {
50-
history.replace(
51-
generatePath(getClusterPrefixedPath(), {
52-
cluster: getCluster() as string,
53-
})
54-
);
51+
if (location.state && location.state.from) {
52+
history.replace(location.state.from);
53+
} else {
54+
history.replace(
55+
generatePath(getClusterPrefixedPath(), {
56+
cluster: getCluster() as string,
57+
})
58+
);
59+
}
5560
} else {
5661
setToken('');
5762
setShowError(true);

0 commit comments

Comments
 (0)