Skip to content

Commit 6102094

Browse files
benmartebexsoftdvaldivia
authored
Adds a logout view which enables minio to logout when using OIDC (#2281)
* added logout view * Fixed issues that arose after merging with master * removed unused navigate and merged with master * changes based on review feedback Co-authored-by: Alex <33497058+bexsoft@users.noreply.github.com> Co-authored-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
1 parent d84062b commit 6102094

File tree

4 files changed

+59
-41
lines changed

4 files changed

+59
-41
lines changed

portal-ui/src/MainRouter.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import AppConsole from "./screens/Console/ConsoleKBar";
2222
import { baseUrl } from "./history";
2323

2424
const Login = React.lazy(() => import("./screens/LoginPage/LoginPage"));
25+
const Logout = React.lazy(() => import("./screens/LogoutPage/LogoutPage"));
2526
const LoginCallback = React.lazy(
2627
() => import("./screens/LoginPage/LoginCallback")
2728
);
@@ -38,6 +39,7 @@ const MainRouter = () => {
3839
</Suspense>
3940
}
4041
/>
42+
<Route path="/logout" element={<Logout />} />
4143
<Route
4244
path="/login"
4345
element={

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ import { IAM_PAGES } from "../../../common/SecureComponent/permissions";
3434

3535
const ConsoleMenuList = ({
3636
menuItems,
37-
onLogoutClick,
3837
isOpen,
3938
}: {
4039
menuItems: any[];
4140
isOpen: boolean;
42-
onLogoutClick: () => void;
4341
}) => {
4442
const stateClsName = isOpen ? "wide" : "mini";
4543
const { pathname = "" } = useLocation();
@@ -136,7 +134,8 @@ const ConsoleMenuList = ({
136134
>
137135
<ListItem
138136
button
139-
onClick={onLogoutClick}
137+
component="a"
138+
href="/logout"
140139
disableRipple
141140
sx={{
142141
...menuItemContainerStyles,

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

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,18 @@
1616

1717
import React from "react";
1818
import { useSelector } from "react-redux";
19-
import { useNavigate } from "react-router-dom";
2019
import { Drawer } from "@mui/material";
2120
import withStyles from "@mui/styles/withStyles";
2221
import { Theme } from "@mui/material/styles";
2322
import createStyles from "@mui/styles/createStyles";
2423
import clsx from "clsx";
2524
import { AppState, useAppDispatch } from "../../../store";
2625

27-
import { ErrorResponseHandler } from "../../../common/types";
28-
import { clearSession } from "../../../common/utils";
29-
import api from "../../../common/api";
30-
3126
import MenuToggle from "./MenuToggle";
3227
import ConsoleMenuList from "./ConsoleMenuList";
3328
import { validRoutes } from "../valid-routes";
34-
import {
35-
menuOpen,
36-
selDirectPVMode,
37-
selOpMode,
38-
userLogged,
39-
} from "../../../systemSlice";
40-
import { resetSession, selFeatures } from "../consoleSlice";
29+
import { menuOpen, selDirectPVMode, selOpMode } from "../../../systemSlice";
30+
import { selFeatures } from "../consoleSlice";
4131

4232
const drawerWidth = 250;
4333

@@ -94,8 +84,6 @@ interface IMenuProps {
9484

9585
const Menu = ({ classes }: IMenuProps) => {
9686
const dispatch = useAppDispatch();
97-
const navigate = useNavigate();
98-
9987
const features = useSelector(selFeatures);
10088

10189
const sidebarOpen = useSelector(
@@ -104,25 +92,6 @@ const Menu = ({ classes }: IMenuProps) => {
10492
const operatorMode = useSelector(selOpMode);
10593
const directPVMode = useSelector(selDirectPVMode);
10694

107-
const logout = () => {
108-
const deleteSession = () => {
109-
clearSession();
110-
dispatch(userLogged(false));
111-
localStorage.setItem("userLoggedIn", "");
112-
localStorage.setItem("redirect-path", "");
113-
dispatch(resetSession());
114-
navigate(`login`);
115-
};
116-
api
117-
.invoke("POST", `/api/v1/logout`)
118-
.then(() => {
119-
deleteSession();
120-
})
121-
.catch((err: ErrorResponseHandler) => {
122-
console.log(err);
123-
deleteSession();
124-
});
125-
};
12695
const allowedMenuItems = validRoutes(features, operatorMode, directPVMode);
12796

12897
return (
@@ -147,11 +116,7 @@ const Menu = ({ classes }: IMenuProps) => {
147116
isOpen={sidebarOpen}
148117
/>
149118

150-
<ConsoleMenuList
151-
menuItems={allowedMenuItems}
152-
isOpen={sidebarOpen}
153-
onLogoutClick={logout}
154-
/>
119+
<ConsoleMenuList menuItems={allowedMenuItems} isOpen={sidebarOpen} />
155120
</Drawer>
156121
);
157122
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// This file is part of MinIO Console Server
2+
// Copyright (c) 2022 MinIO, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
import React from "react";
18+
import { useNavigate } from "react-router-dom";
19+
import { useAppDispatch } from "../../store";
20+
import { ErrorResponseHandler } from "../../common/types";
21+
import { clearSession } from "../../common/utils";
22+
import api from "../../common/api";
23+
import { userLogged } from "../../systemSlice";
24+
import { resetSession } from "../Console/consoleSlice";
25+
26+
const LogoutPage = () => {
27+
const dispatch = useAppDispatch();
28+
const navigate = useNavigate();
29+
const logout = () => {
30+
const deleteSession = () => {
31+
clearSession();
32+
dispatch(userLogged(false));
33+
localStorage.setItem("userLoggedIn", "");
34+
localStorage.setItem("redirect-path", "");
35+
dispatch(resetSession());
36+
navigate(`login`);
37+
};
38+
api
39+
.invoke("POST", `/api/v1/logout`)
40+
.then(() => {
41+
deleteSession();
42+
})
43+
.catch((err: ErrorResponseHandler) => {
44+
console.log(err);
45+
deleteSession();
46+
});
47+
};
48+
logout();
49+
return <></>;
50+
};
51+
52+
export default LogoutPage;

0 commit comments

Comments
 (0)