From 6102094c9ebd1fbc774c87dce6dcac9ed7c975a2 Mon Sep 17 00:00:00 2001 From: Benjamin Marte <693275+benmarte@users.noreply.github.com> Date: Fri, 16 Sep 2022 17:21:58 -0400 Subject: [PATCH] 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> --- portal-ui/src/MainRouter.tsx | 2 + .../screens/Console/Menu/ConsoleMenuList.tsx | 5 +- portal-ui/src/screens/Console/Menu/Menu.tsx | 41 ++------------- .../src/screens/LogoutPage/LogoutPage.tsx | 52 +++++++++++++++++++ 4 files changed, 59 insertions(+), 41 deletions(-) create mode 100644 portal-ui/src/screens/LogoutPage/LogoutPage.tsx diff --git a/portal-ui/src/MainRouter.tsx b/portal-ui/src/MainRouter.tsx index be119f045..23d38f756 100644 --- a/portal-ui/src/MainRouter.tsx +++ b/portal-ui/src/MainRouter.tsx @@ -22,6 +22,7 @@ import AppConsole from "./screens/Console/ConsoleKBar"; import { baseUrl } from "./history"; const Login = React.lazy(() => import("./screens/LoginPage/LoginPage")); +const Logout = React.lazy(() => import("./screens/LogoutPage/LogoutPage")); const LoginCallback = React.lazy( () => import("./screens/LoginPage/LoginCallback") ); @@ -38,6 +39,7 @@ const MainRouter = () => { } /> + } /> void; }) => { const stateClsName = isOpen ? "wide" : "mini"; const { pathname = "" } = useLocation(); @@ -136,7 +134,8 @@ const ConsoleMenuList = ({ > { const dispatch = useAppDispatch(); - const navigate = useNavigate(); - const features = useSelector(selFeatures); const sidebarOpen = useSelector( @@ -104,25 +92,6 @@ const Menu = ({ classes }: IMenuProps) => { const operatorMode = useSelector(selOpMode); const directPVMode = useSelector(selDirectPVMode); - const logout = () => { - const deleteSession = () => { - clearSession(); - dispatch(userLogged(false)); - localStorage.setItem("userLoggedIn", ""); - localStorage.setItem("redirect-path", ""); - dispatch(resetSession()); - navigate(`login`); - }; - api - .invoke("POST", `/api/v1/logout`) - .then(() => { - deleteSession(); - }) - .catch((err: ErrorResponseHandler) => { - console.log(err); - deleteSession(); - }); - }; const allowedMenuItems = validRoutes(features, operatorMode, directPVMode); return ( @@ -147,11 +116,7 @@ const Menu = ({ classes }: IMenuProps) => { isOpen={sidebarOpen} /> - + ); }; diff --git a/portal-ui/src/screens/LogoutPage/LogoutPage.tsx b/portal-ui/src/screens/LogoutPage/LogoutPage.tsx new file mode 100644 index 000000000..ea2cd2963 --- /dev/null +++ b/portal-ui/src/screens/LogoutPage/LogoutPage.tsx @@ -0,0 +1,52 @@ +// This file is part of MinIO Console Server +// Copyright (c) 2022 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +import React from "react"; +import { useNavigate } from "react-router-dom"; +import { useAppDispatch } from "../../store"; +import { ErrorResponseHandler } from "../../common/types"; +import { clearSession } from "../../common/utils"; +import api from "../../common/api"; +import { userLogged } from "../../systemSlice"; +import { resetSession } from "../Console/consoleSlice"; + +const LogoutPage = () => { + const dispatch = useAppDispatch(); + const navigate = useNavigate(); + const logout = () => { + const deleteSession = () => { + clearSession(); + dispatch(userLogged(false)); + localStorage.setItem("userLoggedIn", ""); + localStorage.setItem("redirect-path", ""); + dispatch(resetSession()); + navigate(`login`); + }; + api + .invoke("POST", `/api/v1/logout`) + .then(() => { + deleteSession(); + }) + .catch((err: ErrorResponseHandler) => { + console.log(err); + deleteSession(); + }); + }; + logout(); + return <>; +}; + +export default LogoutPage;