bugfix: check if user exists before create a new refresh token (#3076)

check if user exists before create a new refresh token
This commit is contained in:
Cristhian Zanforlin Lousa 2024-07-31 16:50:10 -03:00 committed by GitHub
commit d7aed90e5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 19 deletions

View file

@ -46,18 +46,18 @@ function ApiInterceptor() {
await tryToRenewAccessToken(error);
const accessToken = cookies.get(LANGFLOW_ACCESS_TOKEN);
if (!accessToken && error?.config?.url?.includes("login")) {
return Promise.reject(error);
}
await remakeRequest(error);
setSaveLoading(false);
authenticationErrorCount = 0;
}
}
await clearBuildVerticesState(error);
return Promise.reject(error);
if (
error?.response?.status !== 401 &&
error?.response?.status !== 403
) {
return Promise.reject(error);
}
},
);
@ -141,21 +141,30 @@ function ApiInterceptor() {
}
async function tryToRenewAccessToken(error: AxiosError) {
try {
if (window.location.pathname.includes("/login")) return;
mutationRenewAccessToken({});
} catch (error) {
clearBuildVerticesState(error);
mutationLogout(undefined, {
onSuccess: () => {
logout();
if (window.location.pathname.includes("/login")) return;
mutationRenewAccessToken(
{},
{
onSuccess: async (data) => {
authenticationErrorCount = 0;
await remakeRequest(error);
setSaveLoading(false);
authenticationErrorCount = 0;
},
onError: (error) => {
console.error(error);
mutationLogout(undefined, {
onSuccess: () => {
logout();
},
onError: (error) => {
console.error(error);
},
});
return Promise.reject("Authentication error");
},
});
return Promise.reject("Authentication error");
}
},
);
}
async function clearBuildVerticesState(error) {