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:
parent
3faf4fc7c8
commit
ac7dcd4b7d
1 changed files with 12 additions and 1 deletions
|
|
@ -1,6 +1,11 @@
|
||||||
import useAuthStore from "@/stores/authStore";
|
import useAuthStore from "@/stores/authStore";
|
||||||
import { useMutationFunctionType } from "@/types/api";
|
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 { api } from "../../api";
|
||||||
import { getURL } from "../../helpers/constants";
|
import { getURL } from "../../helpers/constants";
|
||||||
import { UseRequestProcessor } from "../../services/request-processor";
|
import { UseRequestProcessor } from "../../services/request-processor";
|
||||||
|
|
@ -9,10 +14,16 @@ export const useLogout: useMutationFunctionType<undefined, void> = (
|
||||||
options?,
|
options?,
|
||||||
) => {
|
) => {
|
||||||
const { mutate } = UseRequestProcessor();
|
const { mutate } = UseRequestProcessor();
|
||||||
|
const cookies = new Cookies();
|
||||||
const logout = useAuthStore((state) => state.logout);
|
const logout = useAuthStore((state) => state.logout);
|
||||||
|
const isAutoLoginEnv = IS_AUTO_LOGIN;
|
||||||
|
|
||||||
async function logoutUser(): Promise<any> {
|
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) {
|
if (autoLogin) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue