diff --git a/src/shared/orgListUtil.ts b/src/shared/orgListUtil.ts index 4e24b35c..9197475f 100644 --- a/src/shared/orgListUtil.ts +++ b/src/shared/orgListUtil.ts @@ -142,6 +142,10 @@ export class OrgListUtil { filename.match(/^00D.{15}\.json$/g) ); + // Get default org configuration to always include it even if it's a secondary user + const configAggregator = await ConfigAggregator.create(); + const defaultOrg = configAggregator.getPropertyValue(OrgConfigProperties.TARGET_ORG); + const allAuths: Array = await Promise.all( fileNames.map(async (fileName) => { try { @@ -169,6 +173,13 @@ export class OrgListUtil { usernames: string[]; }; const usernames = orgFileContent.usernames; + + // Always include the default org, even if it's a secondary user + if (defaultOrg === auth.getFields().username) { + return auth; + } + + // Otherwise, only include primary users (first in the usernames array) if (usernames && usernames[0] === auth.getFields().username) { return auth; } @@ -241,6 +252,7 @@ export class OrgListUtil { 'CreatedBy.Username', 'SignupUsername', 'LoginUrl', + 'ScratchOrg', ]; try { @@ -266,8 +278,14 @@ export class OrgListUtil { ): Promise { const contentMap = new Map(updatedContents.map((org) => [org.SignupUsername, org])); + // Also create map by ScratchOrg (orgId) to handle cases where user authenticated as different user + const contentMapByOrgId = new Map(updatedContents.map((org) => [org.ScratchOrg, org])); + const results = orgs.map((scratchOrgInfo): FullyPopulatedScratchOrgFields | string => { - const updatedOrgInfo = contentMap.get(scratchOrgInfo.username); + // Try to match by username first, then by orgId + const updatedOrgInfo = + contentMap.get(scratchOrgInfo.username) ?? contentMapByOrgId.get(trimTo15(scratchOrgInfo.orgId)); + return updatedOrgInfo ? { ...scratchOrgInfo,