diff --git a/src/frontend/src/components/authorization/authGuard/index.tsx b/src/frontend/src/components/authorization/authGuard/index.tsx index 418d4561d..f01529301 100644 --- a/src/frontend/src/components/authorization/authGuard/index.tsx +++ b/src/frontend/src/components/authorization/authGuard/index.tsx @@ -31,7 +31,18 @@ export const ProtectedRoute = ({ children }) => { } }, [isAuthenticated]); if (!isAuthenticated && autoLogin !== undefined && !autoLogin) { - return ; + const currentPath = window.location.pathname; + const isHomePath = currentPath === "/" || currentPath === "/flows"; + const isLoginPage = location.pathname.includes("login"); + return ( + + ); } else { return children; } diff --git a/src/frontend/src/components/authorization/authLoginGuard/index.tsx b/src/frontend/src/components/authorization/authLoginGuard/index.tsx index 9c2c99beb..daf0628de 100644 --- a/src/frontend/src/components/authorization/authLoginGuard/index.tsx +++ b/src/frontend/src/components/authorization/authLoginGuard/index.tsx @@ -5,12 +5,14 @@ export const ProtectedLoginRoute = ({ children }) => { const autoLogin = useAuthStore((state) => state.autoLogin); const isAuthenticated = useAuthStore((state) => state.isAuthenticated); - if (autoLogin === true) { - return ; - } + if (autoLogin === true || isAuthenticated) { + const urlParams = new URLSearchParams(window.location.search); + const redirectPath = urlParams.get("redirect"); - if (isAuthenticated) { - return ; + if (redirectPath) { + return ; + } + return ; } return children; diff --git a/src/frontend/src/controllers/API/queries/auth/use-get-autologin.ts b/src/frontend/src/controllers/API/queries/auth/use-get-autologin.ts index c6bf6e63b..e5b9888a1 100644 --- a/src/frontend/src/controllers/API/queries/auth/use-get-autologin.ts +++ b/src/frontend/src/controllers/API/queries/auth/use-get-autologin.ts @@ -44,7 +44,12 @@ export const useGetAutoLogin: useQueryFunctionType = ( if (!isLoginPage) { if (!isAuthenticated) { await mutationLogout(); - navigate("/login"); + const currentPath = window.location.pathname; + const isHomePath = currentPath === "/" || currentPath === "/flows"; + navigate( + "/login" + + (!isHomePath && !isLoginPage ? "?redirect=" + currentPath : ""), + ); } else { getUser(); }