Skip to content

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

follow same pattern for redirect as PKI

Matheus Nogueira99f7deae1520
diff --git a/frontend/src/hooks/api/secretScanningV2/queries.tsx b/frontend/src/hooks/api/secretScanningV2/queries.tsx
index 83979a0cf4..08a799ff2e 100644
--- a/frontend/src/hooks/api/secretScanningV2/queries.tsx
+++ b/frontend/src/hooks/api/secretScanningV2/queries.tsx
@@ -85,6 +85,16 @@ export const useGetSecretScanningInstanceState = (
enabled: Boolean(orgId) && enabled
});
+export const useGetSecretScanningProjectId = (
+ orgId: string,
+ { enabled = true }: { enabled?: boolean } = {}
+) =>
+ useQuery({
+ queryKey: secretScanningV2Keys.activeProjectId(orgId),
+ queryFn: fetchSecretScanningProjectId,
+ enabled: Boolean(orgId) && enabled
+ });
+
export const useSecretScanningDataSourceOptions = (
options?: Omit<
UseQueryOptions<
diff --git a/frontend/src/pages/organization/ProjectsPage/ProjectTypePage/ProjectTypePage.tsx b/frontend/src/pages/organization/ProjectsPage/ProjectTypePage/ProjectTypePage.tsx
index b292fb7f4d..60187a36c0 100644
--- a/frontend/src/pages/organization/ProjectsPage/ProjectTypePage/ProjectTypePage.tsx
+++ b/frontend/src/pages/organization/ProjectsPage/ProjectTypePage/ProjectTypePage.tsx
@@ -106,6 +106,7 @@ import {
ProjectVersion,
SearchProjectSortBy
} from "@app/hooks/api/projects/types";
+import { useGetSecretScanningProjectId } from "@app/hooks/api/secretScanningV2";
import { useUpdateUserProjectFavorites } from "@app/hooks/api/users/mutation";
import { useGetUserProjectFavorites } from "@app/hooks/api/users/queries";
import {
@@ -257,6 +258,21 @@ export const ProjectTypePage = () => {
}
}, [projectType, certManagerInstance, orgId, navigate]);
+ // Resolving also creates the project for older orgs that never opened Secret Scanning. Non-members land
+ // on the product's access page, which offers joining or requesting access.
+ const { data: secretScanningProjectId } = useGetSecretScanningProjectId(orgId, {
+ enabled: projectType === ProjectType.SecretScanning
+ });
+
+ useEffect(() => {
+ if (projectType === ProjectType.SecretScanning && secretScanningProjectId) {
+ navigate({
+ to: "/organizations/$orgId/projects/secret-scanning/$projectId/data-sources",
+ params: { orgId, projectId: secretScanningProjectId }
+ });
+ }
+ }, [projectType, secretScanningProjectId, orgId, navigate]);
+
useEffect(() => {
if (projectType === ProjectType.PAM) {
navigate({
@@ -294,7 +310,11 @@ export const ProjectTypePage = () => {
);
}
- if (projectType === ProjectType.PAM || projectType === ProjectType.AgentVault) {
+ if (
+ projectType === ProjectType.PAM ||
+ projectType === ProjectType.AgentVault ||
+ projectType === ProjectType.SecretScanning
+ ) {
return null;
}
@@ -1307,31 +1327,6 @@ const EmptyState = ({
isAddingProjectsAllowed: boolean;
}) => {
const typeTitle = getProjectTitle(projectType);
- const { permission } = useOrgPermission();
-
- if (projectType === ProjectType.SecretScanning) {
- const canRequestAccess = permission.can(
- OrgPermissionProjectActions.RequestAccess,
- OrgPermissionSubjects.Project
- );
-
- return (
- <Empty className="border">
- <EmptyHeader>
- <EmptyMedia variant="icon">
- <ProductIcon />
- </EmptyMedia>
- <EmptyTitle>You don&apos;t have access to Secret Scanning</EmptyTitle>
- <EmptyDescription>
- {canRequestAccess
- ? "Switch to All Projects to request access to the Secret Scanning project."
- : "Ask an organization admin to add you to the Secret Scanning project."}
- </EmptyDescription>
- </EmptyHeader>
- </Empty>
- );
- }
-
return (
<Empty className="border">
<EmptyHeader>
diff --git a/frontend/src/pages/organization/ProjectsPage/ProjectTypePage/route.tsx b/frontend/src/pages/organization/ProjectsPage/ProjectTypePage/route.tsx
index b7874d8066..05dba0f163 100644
--- a/frontend/src/pages/organization/ProjectsPage/ProjectTypePage/route.tsx
+++ b/frontend/src/pages/organization/ProjectsPage/ProjectTypePage/route.tsx
@@ -1,27 +1,6 @@
-import { createMongoAbility, MongoAbility, RawRuleOf } from "@casl/ability";
-import { unpackRules } from "@casl/ability/extra";
import { createFileRoute, redirect } from "@tanstack/react-router";
-import axios from "axios";
-import {
- OrgPermissionAdminConsoleAction,
- OrgPermissionSet,
- OrgPermissionSubjects
-} from "@app/context/OrgPermissionContext/types";
import { urlSlugToProjectType } from "@app/helpers/project";
-import { projectKeys } from "@app/hooks/api";
-import { grantOrgAdminProjectAccess } from "@app/hooks/api/orgAdmin";
-import { ProjectType } from "@app/hooks/api/projects/types";
-import { conditionsMatcher } from "@app/hooks/api/roles/permission-matcher";
-import {
- fetchUserOrgPermissions,
- fetchUserProjectPermissions,
- roleQueryKeys
-} from "@app/hooks/api/roles/queries";
-import {
- fetchSecretScanningProjectId,
- secretScanningV2Keys
-} from "@app/hooks/api/secretScanningV2/queries";
import { ProjectTypePage } from "./ProjectTypePage";
@@ -36,7 +15,7 @@ export const Route = createFileRoute(
}
]
}),
- beforeLoad: async ({ params, context }) => {
+ beforeLoad: ({ params }) => {
const projectType = urlSlugToProjectType(params.type);
if (!projectType) {
throw redirect({
@@ -44,63 +23,5 @@ export const Route = createFileRoute(
params: { orgId: params.orgId }
});
}
-
- if (projectType !== ProjectType.SecretScanning) return;
-
- // Secret Scanning has one active project per org, so members skip the list. Resolving can create the
- // project, which the cached project list cannot know about yet, so access is decided by loading the
- // user's permissions on it, as the PAM layout does.
- let projectId: string;
- try {
- projectId = await context.queryClient.fetchQuery({
- queryKey: secretScanningV2Keys.activeProjectId(params.orgId),
- queryFn: fetchSecretScanningProjectId
- });
- } catch {
- return;
- }
-
- const toProject = redirect({
- to: "/organizations/$orgId/projects/secret-scanning/$projectId/data-sources",
- params: { orgId: params.orgId, projectId }
- });
-
- try {
- await context.queryClient.ensureQueryData({
- queryKey: roleQueryKeys.getUserProjectPermissions({ projectId }),
- queryFn: () => fetchUserProjectPermissions({ projectId }),
- retry: false
- });
- } catch (err) {
- // Only a missing membership leads to a join: grant-admin-access replaces an existing member's
- // roles with Admin, so any other failure must stay an error.
- const isNotAMember =
- axios.isAxiosError(err) && err.response?.data?.error === "ProjectMembershipNotFound";
- if (!isNotAMember) throw err;
-
- const orgPermissions = await context.queryClient.ensureQueryData({
- queryKey: roleQueryKeys.getUserOrgPermissions({ orgId: params.orgId }),
- queryFn: () => fetchUserOrgPermissions({ orgId: params.orgId })
- });
- const orgAbility = createMongoAbility<OrgPermissionSet>(
- unpackRules<RawRuleOf<MongoAbility<OrgPermissionSet>>>(orgPermissions.permissions),
- { conditionsMatcher }
- );
- const isOrgAdmin = orgAbility.can(
- OrgPermissionAdminConsoleAction.AccessAllProjects,
- OrgPermissionSubjects.AdminConsole
- );
-
- // Org admins promoted after the project was created are not seeded into it, so they join here, as
- // the home card does. Everyone else stays on the list to request access.
- if (isOrgAdmin) await grantOrgAdminProjectAccess({ projectId });
-
- // The cached project list predates this join or a project created just now.
- await context.queryClient.invalidateQueries({ queryKey: projectKeys.allProjectQueries() });
-
- if (!isOrgAdmin) return;
- }
-
- throw toProject;
}
});