Skip to content

Commit 4dfb79f

Browse files
committed
Fix the relative login redirects
Signed-off-by: Daniel Valdivia <[email protected]>
1 parent 82a0b67 commit 4dfb79f

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

portal-ui/src/ProtectedRoutes.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import useApi from "./screens/Console/Common/Hooks/useApi";
3232
import { ErrorResponseHandler } from "./common/types";
3333
import { ReplicationSite } from "./screens/Console/Configurations/SiteReplication/SiteReplication";
3434
import { SRInfoStateType } from "./types";
35+
import { baseUrl } from "./history";
3536

3637
interface ProtectedRouteProps {
3738
loggedIn: boolean;
@@ -113,7 +114,11 @@ const ProtectedRoute = ({
113114
return null;
114115
}
115116
// redirect user to the right page based on session status
116-
return loggedIn ? <Component /> : <Redirect to={{ pathname: "login" }} />;
117+
return loggedIn ? (
118+
<Component />
119+
) : (
120+
<Redirect to={{ pathname: `${baseUrl}login` }} />
121+
);
117122
};
118123

119124
const mapState = (state: AppState) => ({

portal-ui/src/common/api/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import request from "superagent";
1818
import get from "lodash/get";
1919
import { clearSession } from "../utils";
2020
import { ErrorResponseHandler } from "../types";
21+
import { baseUrl } from "../../history";
2122

2223
export class API {
2324
invoke(method: string, url: string, data?: object) {
@@ -37,7 +38,7 @@ export class API {
3738
clearSession();
3839
// Refresh the whole page to ensure cache is clear
3940
// and we dont end on an infinite loop
40-
window.location.href = "login";
41+
window.location.href = `${baseUrl}login`;
4142
return;
4243
}
4344
return this.onError(err);
@@ -71,7 +72,7 @@ export class API {
7172
return Promise.reject(throwMessage);
7273
} else {
7374
clearSession();
74-
window.location.href = "login";
75+
window.location.href = `${baseUrl}login`;
7576
}
7677
}
7778
}

portal-ui/src/history.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { BrowserHistoryBuildOptions } from "history/createBrowserHistory";
44
let browserHistoryOpts: BrowserHistoryBuildOptions = {};
55

66
let basename = document.baseURI.replace(window.location.origin, "");
7+
// check if we are using base path, if not this always is `/`
8+
const baseLocation = new URL(document.baseURI);
9+
export const baseUrl = baseLocation.pathname;
710

811
if (basename !== "") {
912
browserHistoryOpts.basename = basename;

portal-ui/src/screens/Console/Menu/Menu.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { setMenuOpen, userLoggedIn } from "../../../actions";
2727
import { ErrorResponseHandler } from "../../../common/types";
2828
import { clearSession } from "../../../common/utils";
2929

30-
import history from "../../../history";
30+
import history, { baseUrl } from "../../../history";
3131
import api from "../../../common/api";
3232

3333
import { resetSession } from "../actions";
@@ -106,8 +106,9 @@ const Menu = ({
106106
clearSession();
107107
userLoggedIn(false);
108108
localStorage.setItem("userLoggedIn", "");
109+
localStorage.setItem("redirect-path", "");
109110
resetSession();
110-
history.push("login");
111+
history.push(`${baseUrl}login`);
111112
};
112113
api
113114
.invoke("POST", `/api/v1/logout`)

portal-ui/src/screens/LoginPage/LoginCallback.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import api from "../../common/api";
1919
import withStyles from "@mui/styles/withStyles";
2020
import { Theme } from "@mui/material/styles";
2121
import createStyles from "@mui/styles/createStyles";
22-
import history from "../../history";
22+
import history, { baseUrl } from "../../history";
2323
import { Paper } from "@mui/material";
2424
import Grid from "@mui/material/Grid";
2525
import Typography from "@mui/material/Typography";
@@ -175,7 +175,7 @@ const LoginCallback = ({ classes }: ILoginCallBackProps) => {
175175
</Typography>
176176
<Button
177177
component={"a"}
178-
href="login"
178+
href={`${baseUrl}login`}
179179
type="submit"
180180
variant="contained"
181181
color="primary"

0 commit comments

Comments
 (0)