From 5da6b02801ea0dc8920ccf635bd80bdbd699be27 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Mon, 7 Jun 2021 16:18:16 -0400 Subject: [PATCH] Avoid reload on manual logout --- awx/ui_next/src/App.jsx | 5 +++-- awx/ui_next/src/contexts/Session.jsx | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/awx/ui_next/src/App.jsx b/awx/ui_next/src/App.jsx index 49b2c82987..1ca84a2872 100644 --- a/awx/ui_next/src/App.jsx +++ b/awx/ui_next/src/App.jsx @@ -86,7 +86,7 @@ const AuthorizedRoutes = ({ routeConfig }) => { }; const ProtectedRoute = ({ children, ...rest }) => { - const { setAuthRedirectTo } = useSession(); + const { authRedirectTo, setAuthRedirectTo } = useSession(); const { pathname } = useLocation(); if (isAuthenticated(document.cookie)) { @@ -99,7 +99,8 @@ const ProtectedRoute = ({ children, ...rest }) => { ); } - setAuthRedirectTo(pathname); + setAuthRedirectTo(authRedirectTo === '/logout' ? '/' : pathname); + return ; }; diff --git a/awx/ui_next/src/contexts/Session.jsx b/awx/ui_next/src/contexts/Session.jsx index 6d9b300cf6..e1fef69665 100644 --- a/awx/ui_next/src/contexts/Session.jsx +++ b/awx/ui_next/src/contexts/Session.jsx @@ -74,14 +74,14 @@ function SessionProvider({ children }) { const logout = useCallback(async () => { if (!isSessionExpired.current) { - history.replace('/'); + setAuthRedirectTo('/logout'); } await RootAPI.logout(); setSessionTimeout(0); setSessionCountdown(0); clearTimeout(sessionTimeoutId.current); clearInterval(sessionIntervalId.current); - }, [setSessionTimeout, setSessionCountdown, history]); + }, [setSessionTimeout, setSessionCountdown]); useEffect(() => { if (!isAuthenticated(document.cookie)) {