From c70c10b0df3ced272b75b61303fa3ca215015c01 Mon Sep 17 00:00:00 2001 From: Nathnael Date: Tue, 9 Jun 2026 08:29:09 +0000 Subject: [PATCH] fixes --- apps/edr-freight-web/portal/src/hooks/useAuth.ts | 11 +++++++++-- apps/edr-freight-web/portal/src/utils/api.ts | 3 --- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/edr-freight-web/portal/src/hooks/useAuth.ts b/apps/edr-freight-web/portal/src/hooks/useAuth.ts index 3ce7ec616..67e4385f3 100644 --- a/apps/edr-freight-web/portal/src/hooks/useAuth.ts +++ b/apps/edr-freight-web/portal/src/hooks/useAuth.ts @@ -26,11 +26,14 @@ function getCookie(name: string): string | undefined { const useAuth = () => { const queryClient = useQueryClient(); + const hasToken = !!getCookie("auth-token"); const authQuery = useQuery( api.auth.getMyInfo.queryOptions({ + enabled: hasToken, retry: false, staleTime: 10 * 60 * 1000, + refetchOnWindowFocus: false, }), ); @@ -51,9 +54,13 @@ const useAuth = () => { isUserPending: authQuery.isPending, isCompanyPending: companyQuery.isPending, }); - }, [authQuery, companyQuery]); + }, [ + authQuery.data, + companyQuery.data, + authQuery.isPending, + companyQuery.isPending, + ]); - const hasToken = !!getCookie("auth-token"); const isPending = authQuery.isPending && hasToken; const login = async ( diff --git a/apps/edr-freight-web/portal/src/utils/api.ts b/apps/edr-freight-web/portal/src/utils/api.ts index 2523eb94c..446eec591 100644 --- a/apps/edr-freight-web/portal/src/utils/api.ts +++ b/apps/edr-freight-web/portal/src/utils/api.ts @@ -113,9 +113,6 @@ client.interceptors.response.use( } catch (refreshError) { processQueue(refreshError, undefined); clearAuthCookies(); - if (window.location.pathname !== "/login") { - window.location.href = "/login"; - } return Promise.reject(refreshError); } finally { isRefreshing = false;