fix: prevent logout when auto-login is true (#7209)

* 📝 (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
This commit is contained in:
Cristhian Zanforlin Lousa 2025-03-21 10:38:52 -03:00 committed by GitHub
commit ac7dcd4b7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<undefined, void> = (
options?,
) => {
const { mutate } = UseRequestProcessor();
const cookies = new Cookies();
const logout = useAuthStore((state) => state.logout);
const isAutoLoginEnv = IS_AUTO_LOGIN;
async function logoutUser(): Promise<any> {
const autoLogin = useAuthStore.getState().autoLogin;
const autoLogin =
useAuthStore.getState().autoLogin ||
cookies.get(LANGFLOW_AUTO_LOGIN_OPTION) === "auto" ||
isAutoLoginEnv;
if (autoLogin) {
return {};
}