Skip to content

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

fix(auth): skip auto-select in org selector when org has sub-orgs

Igor Correa6f0ae12a975c
diff --git a/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx b/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx
index 8bfb8dd885..af18103864 100644
--- a/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx
+++ b/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx
@@ -54,6 +54,15 @@ export const SelectOrganizationSection = () => {
const mfaPending = queryParams.get("mfa_pending") === "true";
const defaultSelectedOrg = organizations.data?.find((org) => org.id === orgId);
+ // True when we should auto-select defaultSelectedOrg and bypass the selector UI:
+ // only when there's no CLI callbackPort AND the org has no sub-orgs to choose from.
+ const willAutoSelectDefaultOrg = useMemo(() => {
+ if (!defaultSelectedOrg || callbackPort) return false;
+ if (orgsWithSubOrgs.isPending) return true; // still loading — keep spinner
+ const orgEntry = orgsWithSubOrgs.data?.find((o) => o.id === defaultSelectedOrg.id);
+ return (orgEntry?.subOrganizations.length ?? 0) === 0;
+ }, [defaultSelectedOrg, callbackPort, orgsWithSubOrgs.isPending, orgsWithSubOrgs.data]);
+
const logout = useLogoutUser(true);
const handleLogout = useCallback(async () => {
try {
@@ -311,10 +320,10 @@ export const SelectOrganizationSection = () => {
}
}
- if (defaultSelectedOrg) {
+ if (willAutoSelectDefaultOrg && defaultSelectedOrg) {
handleSelectOrganization(defaultSelectedOrg);
}
- }, [defaultSelectedOrg, mfaPending]);
+ }, [defaultSelectedOrg, mfaPending, willAutoSelectDefaultOrg]);
const renderListContent = () => {
if (orgsWithSubOrgs.isPending) {
@@ -492,7 +501,7 @@ export const SelectOrganizationSection = () => {
if (
userLoading ||
!user ||
- ((isInitialOrgCheckLoading || defaultSelectedOrg) && !shouldShowMfa)
+ ((isInitialOrgCheckLoading || willAutoSelectDefaultOrg) && !shouldShowMfa)
) {
return (
<div className="h-screen w-screen bg-bunker-800">