Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Revert "fix(frontend): invalidate auth token after org select; default query staleTime"

Maidul Islam550b25d0562a
diff --git a/frontend/CLAUDE.md b/frontend/CLAUDE.md
index c46e5f4752..3b277b3959 100644
--- a/frontend/CLAUDE.md
+++ b/frontend/CLAUDE.md
@@ -48,18 +48,6 @@ Each API domain in `src/hooks/api/` (100+ domain folders) follows this structure
HTTP client in `src/config/request.ts`: Axios instance with automatic token injection and 401/403 interceptors.
-#### React Query Global Defaults (`src/hooks/api/reactQuery.tsx`)
-
-The `QueryClient` sets these global defaults for all queries:
-- **`staleTime: 60_000`** (60 seconds) — data fetched within the last 60s is considered fresh and won't be refetched on component mount/remount. This prevents redundant API calls during normal page navigation. Queries that need real-time data (e.g., identity auth configs, dynamic secret leases) override this with `staleTime: 0`.
-- **`refetchOnWindowFocus: false`** — queries do not refetch when the browser tab regains focus.
-- **`retry: 1`** — failed queries retry once.
-
-When adding new queries, consider whether the default 60s staleTime is appropriate:
-- For data that changes only on explicit user action (secrets, folders, org metadata): the 60s default is fine or could be longer.
-- For data that must always be fresh (auth configs, lease TTLs): override with `staleTime: 0, gcTime: 0`.
-- For rarely-changing data (server config, user profile): use `staleTime: Infinity` as the context providers do.
-
### State Management
- **Server state**: TanStack React Query (query key factories in each API domain)
diff --git a/frontend/src/hooks/api/accessApproval/queries.tsx b/frontend/src/hooks/api/accessApproval/queries.tsx
index d9470634a4..2be6c9535f 100644
--- a/frontend/src/hooks/api/accessApproval/queries.tsx
+++ b/frontend/src/hooks/api/accessApproval/queries.tsx
@@ -104,8 +104,7 @@ export const useGetAccessRequestsCount = ({
queryKey: accessApprovalKeys.getAccessApprovalRequestCount(projectSlug, policyId),
queryFn: () => fetchAccessRequestsCount(projectSlug, policyId),
...options,
- enabled: Boolean(projectSlug) && (options?.enabled ?? true),
- refetchInterval: options?.refetchInterval ?? 30_000
+ enabled: Boolean(projectSlug) && (options?.enabled ?? true)
});
export const useGetAccessApprovalPolicies = ({
@@ -132,6 +131,5 @@ export const useGetAccessApprovalRequests = ({
queryFn: () => fetchApprovalRequests({ projectSlug, envSlug, authorUserId }),
...options,
enabled: Boolean(projectSlug) && (options?.enabled ?? true),
- placeholderData: (previousData) => previousData,
- refetchInterval: options?.refetchInterval ?? 30_000
+ placeholderData: (previousData) => previousData
});
diff --git a/frontend/src/hooks/api/auth/queries.tsx b/frontend/src/hooks/api/auth/queries.tsx
index f920941544..488a2667be 100644
--- a/frontend/src/hooks/api/auth/queries.tsx
+++ b/frontend/src/hooks/api/auth/queries.tsx
@@ -101,9 +101,11 @@ export const useSelectOrganization = () => {
return data;
},
onSuccess: () => {
+ // Invalidate the auth token cache so the authenticate middleware
+ // re-calls fetchAuthToken (which reads the new in-memory token with orgId)
queryClient.invalidateQueries({ queryKey: authKeys.getAuthToken });
queryClient.invalidateQueries({ queryKey: organizationKeys.getUserOrganizations });
- queryClient.invalidateQueries({ queryKey: projectKeys.getAllUserProjects() });
+ queryClient.invalidateQueries({ queryKey: projectKeys.getAllUserProjects });
}
});
};
@@ -251,8 +253,6 @@ export const useGetAuthToken = () =>
useQuery({
queryKey: authKeys.getAuthToken,
queryFn: fetchAuthToken,
- staleTime: 0,
- gcTime: 0,
retry: 0
});
diff --git a/frontend/src/hooks/api/dynamicSecretLease/queries.ts b/frontend/src/hooks/api/dynamicSecretLease/queries.ts
index c7e64dbd36..095ece0f73 100644
--- a/frontend/src/hooks/api/dynamicSecretLease/queries.ts
+++ b/frontend/src/hooks/api/dynamicSecretLease/queries.ts
@@ -24,8 +24,6 @@ export const useGetDynamicSecretLeases = ({
dynamicSecretName
}),
enabled: Boolean(projectSlug && environmentSlug && path && dynamicSecretName && enabled),
- staleTime: 0,
- gcTime: 0,
queryFn: async () => {
const { data } = await apiRequest.get<{ leases: TDynamicSecretLease[] }>(
`/api/v1/dynamic-secrets/${dynamicSecretName}/leases`,
diff --git a/frontend/src/hooks/api/identities/queries.tsx b/frontend/src/hooks/api/identities/queries.tsx
index 39e88b338c..5614802ceb 100644
--- a/frontend/src/hooks/api/identities/queries.tsx
+++ b/frontend/src/hooks/api/identities/queries.tsx
@@ -330,11 +330,9 @@ export const useGetIdentityLdapAuth = (
});
};
-export const useGetIdentityTokensTokenAuth = (
- identityId: string,
- options?: TReactQueryOptions["options"]
-) => {
+export const useGetIdentityTokensTokenAuth = (identityId: string) => {
return useQuery({
+ enabled: Boolean(identityId),
queryKey: identitiesKeys.getIdentityTokensTokenAuth(identityId),
queryFn: async () => {
const {
@@ -343,11 +341,7 @@ export const useGetIdentityTokensTokenAuth = (
`/api/v1/auth/token-auth/identities/${identityId}/tokens`
);
return tokens;
- },
- staleTime: 0,
- gcTime: 0,
- ...options,
- enabled: Boolean(identityId) && (options?.enabled ?? true)
+ }
});
};
diff --git a/frontend/src/hooks/api/reactQuery.tsx b/frontend/src/hooks/api/reactQuery.tsx
index b7a558dad2..b80393cf51 100644
--- a/frontend/src/hooks/api/reactQuery.tsx
+++ b/frontend/src/hooks/api/reactQuery.tsx
@@ -220,8 +220,7 @@ export const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
- retry: 1,
- staleTime: 60_000 // 60s — prevents refetch on every component mount/remount
+ retry: 1
}
}
});
diff --git a/frontend/src/hooks/api/secretApprovalRequest/mutation.tsx b/frontend/src/hooks/api/secretApprovalRequest/mutation.tsx
index 52f37848f1..6a03b431ca 100644
--- a/frontend/src/hooks/api/secretApprovalRequest/mutation.tsx
+++ b/frontend/src/hooks/api/secretApprovalRequest/mutation.tsx
@@ -20,10 +20,8 @@ export const useUpdateSecretApprovalReviewStatus = () => {
});
return data;
},
- onSuccess: (_, { id, projectId }) => {
+ onSuccess: (_, { id }) => {
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.detail({ id }) });
- queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.list({ projectId }) });
- queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ projectId }) });
}
});
};
diff --git a/frontend/src/hooks/api/secretApprovalRequest/types.ts b/frontend/src/hooks/api/secretApprovalRequest/types.ts
index e65d3de5e3..38bd1c2796 100644
--- a/frontend/src/hooks/api/secretApprovalRequest/types.ts
+++ b/frontend/src/hooks/api/secretApprovalRequest/types.ts
@@ -134,7 +134,6 @@ export type TUpdateSecretApprovalReviewStatusDTO = {
status: ApprovalStatus;
comment?: string;
id: string;
- projectId: string;
};
export type TUpdateSecretApprovalRequestStatusDTO = {
diff --git a/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/ProjectNav.tsx b/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/ProjectNav.tsx
index add508a3a7..1950782bff 100644
--- a/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/ProjectNav.tsx
+++ b/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/ProjectNav.tsx
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import { useLocation, useNavigate } from "@tanstack/react-router";
import { AnimatePresence, motion } from "framer-motion";
-import { ChevronLeft } from "lucide-react";
+import { ChevronLeft, DoorOpen, FileKey, Shield } from "lucide-react";
import { SidebarGroup, SidebarGroupLabel, SidebarMenu } from "@app/components/v3";
import { useOrganization, useProject } from "@app/context";
@@ -31,7 +31,6 @@ import {
import { ProjectSubmenuView } from "./SubmenuViews";
import type { Submenu } from "./types";
import { PROJECT_TYPE_PATH } from "./types";
-import { useApprovalSubmenu } from "./useApprovalSubmenu";
const PROJECT_NAV_COMPONENT: Record<
ProjectType,
@@ -53,8 +52,6 @@ export const ProjectNav = () => {
const { currentOrg, isSubOrganization } = useOrganization();
const { pathname } = useLocation();
const navigate = useNavigate();
- const { submenu: smApprovalsSubmenu, pendingRequestsCount: smPendingCount } =
- useApprovalSubmenu();
const projectLabel = isSubOrganization ? "Sub-Organization" : "Organization";
const NavComponent = PROJECT_NAV_COMPONENT[currentProject.type];
@@ -93,7 +90,17 @@ export const ProjectNav = () => {
if (isOnCertApprovals) return CERT_APPROVALS_SUBMENU;
if (currentProject.type === ProjectType.PAM && pathname.includes("/approvals"))
return PAM_APPROVALS_SUBMENU;
- if (isOnApproval) return smApprovalsSubmenu;
+ if (isOnApproval)
+ return {
+ title: "Approvals",
+ pathSuffix: "approval",
+ defaultTab: "approval-requests",
+ items: [
+ { label: "Change Requests", icon: FileKey, tab: "approval-requests" },
+ { label: "Access Requests", icon: DoorOpen, tab: "resource-requests" },
+ { label: "Policies", icon: Shield, tab: "policies" }
+ ]
+ };
return null;
};
@@ -103,16 +110,6 @@ export const ProjectNav = () => {
setActiveSubmenu(getInitialProjectSubmenu());
}, [pathname]); // eslint-disable-line react-hooks/exhaustive-deps
- // Keep the active submenu in sync when badge data changes
- useEffect(() => {
- setActiveSubmenu((current) => {
- if (current && current.pathSuffix === smApprovalsSubmenu.pathSuffix) {
- return smApprovalsSubmenu;
- }
- return current;
- });
- }, [smPendingCount]); // eslint-disable-line react-hooks/exhaustive-deps
-
const handleSubmenuOpen = (submenu: Submenu) => {
setActiveSubmenu(submenu);
const typePath = PROJECT_TYPE_PATH[currentProject.type];
diff --git a/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/SecretManagerNav.tsx b/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/SecretManagerNav.tsx
index 7a6f21392a..fd031544fa 100644
--- a/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/SecretManagerNav.tsx
+++ b/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/SecretManagerNav.tsx
@@ -1,8 +1,22 @@
-import { ActivityIcon, BookCheck, FileText, Plug, RefreshCw, Settings, Shield } from "lucide-react";
+import {
+ ActivityIcon,
+ BookCheck,
+ DoorOpen,
+ FileKey,
+ FileText,
+ Plug,
+ RefreshCw,
+ Settings,
+ Shield
+} from "lucide-react";
import { ProjectIcon } from "@app/components/v3";
import { useProject } from "@app/context";
-import { useGetSecretRotations } from "@app/hooks/api";
+import {
+ useGetAccessRequestsCount,
+ useGetSecretApprovalRequestCount,
+ useGetSecretRotations
+} from "@app/hooks/api";
import { ProjectNavList } from "./ProjectNavLink";
import {
@@ -11,21 +25,47 @@ import {
SM_SETTINGS_SUBMENU
} from "./submenus";
import type { NavItem, Submenu } from "./types";
-import { useApprovalSubmenu } from "./useApprovalSubmenu";
export const SecretManagerNav = ({
onSubmenuOpen
}: {
onSubmenuOpen: (submenu: Submenu) => void;
}) => {
- const { projectId } = useProject();
+ const { currentProject, projectId } = useProject();
- const { submenu: approvalsSubmenu, pendingRequestsCount } = useApprovalSubmenu();
+ const { data: secretApprovalReqCount } = useGetSecretApprovalRequestCount({ projectId });
+ const { data: accessApprovalRequestCount } = useGetAccessRequestsCount({
+ projectSlug: currentProject?.slug || ""
+ });
const { data: secretRotations } = useGetSecretRotations({
workspaceId: projectId,
options: { refetchOnMount: false }
});
+ const pendingRequestsCount =
+ (secretApprovalReqCount?.open || 0) + (accessApprovalRequestCount?.pendingCount || 0);
+
+ const approvalsSubmenu: Submenu = {
+ title: "Approvals",
+ pathSuffix: "approval",
+ defaultTab: "approval-requests",
+ items: [
+ {
+ label: "Change Requests",
+ icon: FileKey,
+ tab: "approval-requests",
+ badgeCount: secretApprovalReqCount?.open || undefined
+ },
+ {
+ label: "Access Requests",
+ icon: DoorOpen,
+ tab: "resource-requests",
+ badgeCount: accessApprovalRequestCount?.pendingCount || undefined
+ },
+ { label: "Policies", icon: Shield, tab: "policies" }
+ ]
+ };
+
const items: NavItem[] = [
{
label: "Overview",
diff --git a/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/useApprovalSubmenu.ts b/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/useApprovalSubmenu.ts
deleted file mode 100644
index baf5187a42..0000000000
--- a/frontend/src/layouts/OrganizationLayout/components/OrgSidebar/useApprovalSubmenu.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-import { DoorOpen, FileKey, Shield } from "lucide-react";
-
-import { useProject } from "@app/context";
-import { useGetAccessRequestsCount, useGetSecretApprovalRequestCount } from "@app/hooks/api";
-
-import type { Submenu } from "./types";
-
-export const useApprovalSubmenu = (): {
- submenu: Submenu;
- pendingRequestsCount: number;
-} => {
- const { currentProject, projectId } = useProject();
-
- const { data: secretApprovalReqCount } = useGetSecretApprovalRequestCount({ projectId });
- const { data: accessApprovalRequestCount } = useGetAccessRequestsCount({
- projectSlug: currentProject?.slug || ""
- });
-
- const pendingRequestsCount =
- (secretApprovalReqCount?.open || 0) + (accessApprovalRequestCount?.pendingCount || 0);
-
- return {
- submenu: {
- title: "Approvals",
- pathSuffix: "approval",
- defaultTab: "approval-requests",
- items: [
- {
- label: "Change Requests",
- icon: FileKey,
- tab: "approval-requests",
- badgeCount: secretApprovalReqCount?.open || undefined
- },
- {
- label: "Access Requests",
- icon: DoorOpen,
- tab: "resource-requests",
- badgeCount: accessApprovalRequestCount?.pendingCount || undefined
- },
- { label: "Policies", icon: Shield, tab: "policies" }
- ]
- },
- pendingRequestsCount
- };
-};
diff --git a/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestChanges.tsx b/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestChanges.tsx
index 64cc569125..a26977e242 100644
--- a/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestChanges.tsx
+++ b/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestChanges.tsx
@@ -188,8 +188,7 @@ export const SecretApprovalRequestChanges = ({ approvalRequestId, onGoBack }: Pr
await updateSecretApprovalRequestStatus({
id: approvalRequestId,
status,
- comment,
- projectId
+ comment
});
createNotification({
type: "success",