Skip to content

Commit 64fe3a1

Browse files
authored
Store bucket path if it is redirected to restore on login (#2006)
1 parent a160b92 commit 64fe3a1

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

portal-ui/src/ProtectedRoutes.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
import React, { useEffect, useState } from "react";
18-
import { Redirect } from "react-router-dom";
19-
18+
import { Redirect, useLocation } from "react-router-dom";
2019
import api from "./common/api";
2120
import { ISessionResponse } from "./screens/Console/types";
2221
import useApi from "./screens/Console/Common/Hooks/useApi";
@@ -48,6 +47,13 @@ const ProtectedRoute = ({ Component }: ProtectedRouteProps) => {
4847
const [sessionLoading, setSessionLoading] = useState<boolean>(true);
4948
const userLoggedIn = useSelector((state: AppState) => state.system.loggedIn);
5049

50+
const { pathname = "" } = useLocation();
51+
52+
const StorePathAndRedirect = () => {
53+
localStorage.setItem("redirect-path", pathname);
54+
return <Redirect to={{ pathname: `${baseUrl}login` }} />;
55+
};
56+
5157
useEffect(() => {
5258
api
5359
.invoke("GET", `/api/v1/session`)
@@ -104,11 +110,7 @@ const ProtectedRoute = ({ Component }: ProtectedRouteProps) => {
104110
return null;
105111
}
106112
// redirect user to the right page based on session status
107-
return userLoggedIn ? (
108-
<Component />
109-
) : (
110-
<Redirect to={{ pathname: `${baseUrl}login` }} />
111-
);
113+
return userLoggedIn ? <Component /> : <StorePathAndRedirect />;
112114
};
113115

114116
export default ProtectedRoute;

0 commit comments

Comments
 (0)