From fa04f70b32219c1e65295272b4c807217bec47b7 Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Mon, 11 Mar 2024 19:26:16 -0300 Subject: [PATCH 1/3] bugfix: login on loop when username or password is incorrect --- src/frontend/src/controllers/API/api.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/controllers/API/api.tsx b/src/frontend/src/controllers/API/api.tsx index c64d8df07..0ad67cecb 100644 --- a/src/frontend/src/controllers/API/api.tsx +++ b/src/frontend/src/controllers/API/api.tsx @@ -24,7 +24,10 @@ function ApiInterceptor() { async (error: AxiosError) => { if (error.response?.status === 403 || error.response?.status === 401) { if (!autoLogin) { - checkErrorCount(); + const stillRefresh = checkErrorCount(); + if (!stillRefresh) { + return Promise.reject(error); + } const acceptedRequest = await tryToRenewAccessToken(error); const accessToken = cookies.get("access_token_lf"); @@ -96,7 +99,10 @@ function ApiInterceptor() { if (authenticationErrorCount > 3) { authenticationErrorCount = 0; logout(); + return false; } + + return true; } async function tryToRenewAccessToken(error: AxiosError) { @@ -116,6 +122,7 @@ function ApiInterceptor() { } catch (error) { clearBuildVerticesState(error); logout(); + return Promise.reject("Authentication error"); } } From ff21ecc213ebf5e41e54e3ffd79b9bbd5625ed58 Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Tue, 12 Mar 2024 16:26:09 -0300 Subject: [PATCH 2/3] fix problem of retries on login page --- src/backend/langflow/services/settings/auth.py | 2 +- src/frontend/src/controllers/API/api.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/services/settings/auth.py b/src/backend/langflow/services/settings/auth.py index 8463d0781..8cf543055 100644 --- a/src/backend/langflow/services/settings/auth.py +++ b/src/backend/langflow/services/settings/auth.py @@ -22,7 +22,7 @@ class AuthSettings(BaseSettings): frozen=False, ) ALGORITHM: str = "HS256" - ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 + ACCESS_TOKEN_EXPIRE_MINUTES: int = 1 REFRESH_TOKEN_EXPIRE_MINUTES: int = 60 * 12 * 7 # API Key to execute /process endpoint diff --git a/src/frontend/src/controllers/API/api.tsx b/src/frontend/src/controllers/API/api.tsx index 0ad67cecb..c467d66bb 100644 --- a/src/frontend/src/controllers/API/api.tsx +++ b/src/frontend/src/controllers/API/api.tsx @@ -107,6 +107,7 @@ function ApiInterceptor() { async function tryToRenewAccessToken(error: AxiosError) { try { + if (window.location.pathname.includes("/login")) return; const res = await renewAccessToken(); if (res?.data?.access_token && res?.data?.refresh_token) { login(res?.data?.access_token); From e775df7eef9afab1fbc9bd0402d5e56a4dfea33a Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Tue, 12 Mar 2024 16:26:28 -0300 Subject: [PATCH 3/3] return acces_token to original value --- src/backend/langflow/services/settings/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/langflow/services/settings/auth.py b/src/backend/langflow/services/settings/auth.py index 8cf543055..8463d0781 100644 --- a/src/backend/langflow/services/settings/auth.py +++ b/src/backend/langflow/services/settings/auth.py @@ -22,7 +22,7 @@ class AuthSettings(BaseSettings): frozen=False, ) ALGORITHM: str = "HS256" - ACCESS_TOKEN_EXPIRE_MINUTES: int = 1 + ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 REFRESH_TOKEN_EXPIRE_MINUTES: int = 60 * 12 * 7 # API Key to execute /process endpoint