Skip to content

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

fix: personal org creation fix

varonix0a15c86c5d4b3
diff --git a/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx b/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx
index eb77a0492a..5e2135382e 100644
--- a/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx
+++ b/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx
@@ -452,7 +452,8 @@ export const Navbar = () => {
{/* Current Organization */}
<CommandGroup heading="Current Organization">
<CommandItem
- value={rootOrg.name}
+ value={rootOrg.id}
+ keywords={[rootOrg.name]}
onSelect={() => {
setIsOrgSelectOpen(false);
if (isSubOrganization) {
@@ -513,7 +514,8 @@ export const Navbar = () => {
{subOrganizations.map((subOrg) => (
<CommandItem
key={subOrg.id}
- value={subOrg.name}
+ value={subOrg.id}
+ keywords={[subOrg.name]}
onSelect={() => {
setIsOrgSelectOpen(false);
handleOrgSelection({ organizationId: subOrg.id });
@@ -558,7 +560,8 @@ export const Navbar = () => {
.map((org) => (
<CommandItem
key={org.id}
- value={org.name}
+ value={org.id}
+ keywords={[org.name]}
onSelect={() => {
setIsOrgSelectOpen(false);
handleOrgNav(org);
diff --git a/frontend/src/pages/organization/NoOrgPage/NoOrgPage.tsx b/frontend/src/pages/organization/NoOrgPage/NoOrgPage.tsx
index 041aa31687..5fdcacc224 100644
--- a/frontend/src/pages/organization/NoOrgPage/NoOrgPage.tsx
+++ b/frontend/src/pages/organization/NoOrgPage/NoOrgPage.tsx
@@ -7,18 +7,33 @@ import { useNavigate } from "@tanstack/react-router";
import { createNotification } from "@app/components/notifications";
import { CreateOrgModal } from "@app/components/organization/CreateOrgModal";
import { ContentLoader } from "@app/components/v2";
-import { organizationKeys, useCreateOrg, useSelectOrganization } from "@app/hooks/api";
+import { organizationKeys, useCreateOrg, useGetOrganizations, useSelectOrganization } from "@app/hooks/api";
const PERSONAL_ORG_NAME = "Personal Org";
// A useRef gate resets on a full unmount/remount; this sessionStorage flag survives it, so an
// interrupted-then-remounted page can't fire a second createOrg and leave a duplicate org behind.
const CREATION_STARTED_KEY = "personalOrgCreationStarted";
+const generatePersonalOrgName = (existingNames: string[]) => {
+ const taken = new Set(existingNames.map((name) => name.trim().toLowerCase()));
+ const isTaken = (candidate: string) => taken.has(candidate.trim().toLowerCase());
+
+ if (!isTaken(PERSONAL_ORG_NAME)) return PERSONAL_ORG_NAME;
+
+ let suffix = 1;
+ while (isTaken(`${PERSONAL_ORG_NAME} ${suffix}`)) {
+ suffix += 1;
+ }
+ return `${PERSONAL_ORG_NAME} ${suffix}`;
+};
+
export const NoOrgPage = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const queryClient = useQueryClient();
+ const organizations = useGetOrganizations();
+
const { mutateAsync: createOrg } = useCreateOrg({ invalidate: false });
const { mutateAsync: selectOrg } = useSelectOrganization();
@@ -28,15 +43,19 @@ export const NoOrgPage = () => {
useEffect(() => {
if (hasRun.current) return;
+ if (organizations.isPending) return;
+
hasRun.current = true;
if (sessionStorage.getItem(CREATION_STARTED_KEY)) return;
sessionStorage.setItem(CREATION_STARTED_KEY, "true");
const createPersonalOrg = async () => {
+ const orgName = generatePersonalOrgName((organizations.data ?? []).map((org) => org.name));
+
let organization;
try {
- organization = await createOrg({ name: PERSONAL_ORG_NAME });
+ organization = await createOrg({ name: orgName });
} catch {
// Nothing was created, so reset both guards and let the user create an org manually.
createNotification({
@@ -74,7 +93,7 @@ export const NoOrgPage = () => {
};
createPersonalOrg();
- }, [createOrg, selectOrg, navigate, queryClient]);
+ }, [createOrg, selectOrg, navigate, queryClient, organizations.isPending, organizations.data]);
return (
<>