diff --git a/portal-ui/src/ProtectedRoutes.tsx b/portal-ui/src/ProtectedRoutes.tsx index b38b62fa6..dedd1a84e 100644 --- a/portal-ui/src/ProtectedRoutes.tsx +++ b/portal-ui/src/ProtectedRoutes.tsx @@ -32,6 +32,7 @@ import useApi from "./screens/Console/Common/Hooks/useApi"; import { ErrorResponseHandler } from "./common/types"; import { ReplicationSite } from "./screens/Console/Configurations/SiteReplication/SiteReplication"; import { SRInfoStateType } from "./types"; +import { baseUrl } from "./history"; interface ProtectedRouteProps { loggedIn: boolean; @@ -113,7 +114,11 @@ const ProtectedRoute = ({ return null; } // redirect user to the right page based on session status - return loggedIn ? : ; + return loggedIn ? ( + + ) : ( + + ); }; const mapState = (state: AppState) => ({ diff --git a/portal-ui/src/common/api/index.ts b/portal-ui/src/common/api/index.ts index 375e68db8..0ebe7643a 100644 --- a/portal-ui/src/common/api/index.ts +++ b/portal-ui/src/common/api/index.ts @@ -18,6 +18,7 @@ import request from "superagent"; import get from "lodash/get"; import { clearSession } from "../utils"; import { ErrorResponseHandler } from "../types"; +import { baseUrl } from "../../history"; export class API { invoke(method: string, url: string, data?: object) { @@ -37,7 +38,7 @@ export class API { clearSession(); // Refresh the whole page to ensure cache is clear // and we dont end on an infinite loop - window.location.href = "login"; + window.location.href = `${baseUrl}login`; return; } return this.onError(err); @@ -71,7 +72,7 @@ export class API { return Promise.reject(throwMessage); } else { clearSession(); - window.location.href = "login"; + window.location.href = `${baseUrl}login`; } } } diff --git a/portal-ui/src/history.ts b/portal-ui/src/history.ts index bc3a05e31..7f4ef7614 100644 --- a/portal-ui/src/history.ts +++ b/portal-ui/src/history.ts @@ -4,6 +4,9 @@ import { BrowserHistoryBuildOptions } from "history/createBrowserHistory"; let browserHistoryOpts: BrowserHistoryBuildOptions = {}; let basename = document.baseURI.replace(window.location.origin, ""); +// check if we are using base path, if not this always is `/` +const baseLocation = new URL(document.baseURI); +export const baseUrl = baseLocation.pathname; if (basename !== "") { browserHistoryOpts.basename = basename; diff --git a/portal-ui/src/screens/Console/Menu/Menu.tsx b/portal-ui/src/screens/Console/Menu/Menu.tsx index b6016537b..69dc3bb51 100644 --- a/portal-ui/src/screens/Console/Menu/Menu.tsx +++ b/portal-ui/src/screens/Console/Menu/Menu.tsx @@ -27,7 +27,7 @@ import { setMenuOpen, userLoggedIn } from "../../../actions"; import { ErrorResponseHandler } from "../../../common/types"; import { clearSession } from "../../../common/utils"; -import history from "../../../history"; +import history, { baseUrl } from "../../../history"; import api from "../../../common/api"; import { resetSession } from "../actions"; @@ -106,8 +106,9 @@ const Menu = ({ clearSession(); userLoggedIn(false); localStorage.setItem("userLoggedIn", ""); + localStorage.setItem("redirect-path", ""); resetSession(); - history.push("login"); + history.push(`${baseUrl}login`); }; api .invoke("POST", `/api/v1/logout`) diff --git a/portal-ui/src/screens/LoginPage/LoginCallback.tsx b/portal-ui/src/screens/LoginPage/LoginCallback.tsx index cd36772d8..723baacf1 100644 --- a/portal-ui/src/screens/LoginPage/LoginCallback.tsx +++ b/portal-ui/src/screens/LoginPage/LoginCallback.tsx @@ -19,7 +19,7 @@ import api from "../../common/api"; import withStyles from "@mui/styles/withStyles"; import { Theme } from "@mui/material/styles"; import createStyles from "@mui/styles/createStyles"; -import history from "../../history"; +import history, { baseUrl } from "../../history"; import { Paper } from "@mui/material"; import Grid from "@mui/material/Grid"; import Typography from "@mui/material/Typography"; @@ -175,7 +175,7 @@ const LoginCallback = ({ classes }: ILoginCallBackProps) => {