diff --git a/awx/ui/src/contexts/Session.js b/awx/ui/src/contexts/Session.js
index af34948313..d0a92d7523 100644
--- a/awx/ui/src/contexts/Session.js
+++ b/awx/ui/src/contexts/Session.js
@@ -75,6 +75,7 @@ function SessionProvider({ children }) {
const [sessionCountdown, setSessionCountdown] = useState(0);
const [authRedirectTo, setAuthRedirectTo] = useState('/');
const [isUserBeingLoggedOut, setIsUserBeingLoggedOut] = useState(false);
+ const [isRedirectLinkReceived, setIsRedirectLinkReceived] = useState(false);
const {
request: fetchLoginRedirectOverride,
@@ -99,6 +100,7 @@ function SessionProvider({ children }) {
const logout = useCallback(async () => {
setIsUserBeingLoggedOut(true);
+ setIsRedirectLinkReceived(false);
if (!isSessionExpired.current) {
setAuthRedirectTo('/logout');
window.localStorage.setItem(SESSION_USER_ID, null);
@@ -112,6 +114,18 @@ function SessionProvider({ children }) {
return ;
}, [setSessionTimeout, setSessionCountdown]);
+ useEffect(() => {
+ const unlisten = history.listen((location, action) => {
+ if (action === 'POP') {
+ setIsRedirectLinkReceived(true);
+ }
+ });
+
+ return () => {
+ unlisten(); // ensure that the listener is removed when the component unmounts
+ };
+ }, [history]);
+
useEffect(() => {
if (!isAuthenticated(document.cookie)) {
return () => {};
@@ -176,6 +190,8 @@ function SessionProvider({ children }) {
logout,
sessionCountdown,
setAuthRedirectTo,
+ isRedirectLinkReceived,
+ setIsRedirectLinkReceived,
}),
[
authRedirectTo,
@@ -186,6 +202,8 @@ function SessionProvider({ children }) {
logout,
sessionCountdown,
setAuthRedirectTo,
+ isRedirectLinkReceived,
+ setIsRedirectLinkReceived,
]
);
diff --git a/awx/ui/src/screens/Login/Login.js b/awx/ui/src/screens/Login/Login.js
index 0e9009a10a..6abfa86b61 100644
--- a/awx/ui/src/screens/Login/Login.js
+++ b/awx/ui/src/screens/Login/Login.js
@@ -45,7 +45,8 @@ const Login = styled(PFLogin)`
function AWXLogin({ alt, isAuthenticated }) {
const [userId, setUserId] = useState(null);
- const { authRedirectTo, isSessionExpired } = useSession();
+ const { authRedirectTo, isSessionExpired, isRedirectLinkReceived } =
+ useSession();
const isNewUser = useRef(true);
const hasVerifiedUser = useRef(false);
@@ -179,7 +180,8 @@ function AWXLogin({ alt, isAuthenticated }) {
return ;
}
if (userId && hasVerifiedUser.current) {
- const redirect = isNewUser.current ? '/home' : authRedirectTo;
+ const redirect =
+ isNewUser.current && !isRedirectLinkReceived ? '/home' : authRedirectTo;
return ;
}