@@ -25,7 +25,7 @@ import TextField from '@mui/material/TextField';
2525import Typography from '@mui/material/Typography' ;
2626import React from 'react' ;
2727import { Trans , useTranslation } from 'react-i18next' ;
28- import { generatePath , useHistory } from 'react-router-dom' ;
28+ import { generatePath , useHistory , useLocation } from 'react-router-dom' ;
2929import { setToken } from '../../lib/auth' ;
3030import { getCluster , getClusterPrefixedPath } from '../../lib/cluster' ;
3131import { useClustersConf } from '../../lib/k8s' ;
@@ -37,6 +37,7 @@ import HeadlampLink from '../common/Link';
3737
3838export 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