From ac7dcd4b7d3a12a6bb3de3628280f5d65a6bf24c Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Fri, 21 Mar 2025 10:38:52 -0300 Subject: [PATCH] fix: prevent logout when auto-login is true (#7209) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 📝 (use-post-logout.ts): import Cookies from "react-cookie" to handle cookies in the logout functionality 💡 (use-post-logout.ts): update logic to check for "auto_login_lf" cookie value in addition to autoLogin state before logging out the user * 📝 (use-post-logout.ts): add constants for IS_AUTO_LOGIN and LANGFLOW_AUTO_LOGIN_OPTION for better code readability and maintainability --- .../controllers/API/queries/auth/use-post-logout.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/controllers/API/queries/auth/use-post-logout.ts b/src/frontend/src/controllers/API/queries/auth/use-post-logout.ts index 80aa0c15a..7164a36e8 100644 --- a/src/frontend/src/controllers/API/queries/auth/use-post-logout.ts +++ b/src/frontend/src/controllers/API/queries/auth/use-post-logout.ts @@ -1,6 +1,11 @@ import useAuthStore from "@/stores/authStore"; import { useMutationFunctionType } from "@/types/api"; +import { + IS_AUTO_LOGIN, + LANGFLOW_AUTO_LOGIN_OPTION, +} from "@/constants/constants"; +import { Cookies } from "react-cookie"; import { api } from "../../api"; import { getURL } from "../../helpers/constants"; import { UseRequestProcessor } from "../../services/request-processor"; @@ -9,10 +14,16 @@ export const useLogout: useMutationFunctionType = ( options?, ) => { const { mutate } = UseRequestProcessor(); + const cookies = new Cookies(); const logout = useAuthStore((state) => state.logout); + const isAutoLoginEnv = IS_AUTO_LOGIN; async function logoutUser(): Promise { - const autoLogin = useAuthStore.getState().autoLogin; + const autoLogin = + useAuthStore.getState().autoLogin || + cookies.get(LANGFLOW_AUTO_LOGIN_OPTION) === "auto" || + isAutoLoginEnv; + if (autoLogin) { return {}; }