github.com/minio/console@v1.4.1/web-app/src/screens/LogoutPage/LogoutPage.tsx (about) 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, { useEffect } 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 { userLogged } from "../../systemSlice"; 23 import { resetSession } from "../Console/consoleSlice"; 24 import api from "../../common/api"; 25 import LoadingComponent from "../../common/LoadingComponent"; 26 27 const LogoutPage = () => { 28 const dispatch = useAppDispatch(); 29 const navigate = useNavigate(); 30 useEffect(() => { 31 const deleteSession = () => { 32 dispatch(userLogged(false)); 33 // Disconnect OB Websocket 34 dispatch({ type: "socket/OBDisconnect" }); 35 localStorage.setItem("userLoggedIn", ""); 36 localStorage.setItem("redirect-path", ""); 37 dispatch(resetSession()); 38 clearSession(); 39 40 navigate("/login"); 41 window.location.reload(); //reset-all redux states etc. by force reloading. 42 }; 43 44 const logout = () => { 45 const state = localStorage.getItem("auth-state"); 46 api 47 .invoke("POST", `/api/v1/logout`, { state }) 48 .then(deleteSession) 49 .catch((err: ErrorResponseHandler) => { 50 console.error(err); 51 deleteSession(); 52 }); 53 }; 54 logout(); 55 }, [dispatch, navigate]); 56 return <LoadingComponent />; 57 }; 58 59 export default LogoutPage;