From 32651db4e936eb4733502d5c75fa4b4c5a3a75c4 Mon Sep 17 00:00:00 2001 From: Kia Lam Date: Mon, 27 Sep 2021 10:58:49 -0700 Subject: [PATCH] Wrap `setAuthRedirectTo` in useEffect. --- awx/ui/src/App.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/awx/ui/src/App.js b/awx/ui/src/App.js index 77116d3f8b..06c7085c12 100644 --- a/awx/ui/src/App.js +++ b/awx/ui/src/App.js @@ -102,6 +102,10 @@ const ProtectedRoute = ({ children, ...rest }) => { const { authRedirectTo, setAuthRedirectTo } = useSession(); const { pathname } = useLocation(); + useEffect(() => { + setAuthRedirectTo(authRedirectTo === '/logout' ? '/' : pathname); + }); + if (isAuthenticated(document.cookie)) { return ( @@ -112,8 +116,6 @@ const ProtectedRoute = ({ children, ...rest }) => { ); } - setAuthRedirectTo(authRedirectTo === '/logout' ? '/' : pathname); - return ; };