Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/shared/orgListUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuthInfo | undefined> = await Promise.all(
fileNames.map(async (fileName) => {
try {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -241,6 +252,7 @@ export class OrgListUtil {
'CreatedBy.Username',
'SignupUsername',
'LoginUrl',
'ScratchOrg',
];

try {
Expand All @@ -266,8 +278,14 @@ export class OrgListUtil {
): Promise<FullyPopulatedScratchOrgFields[]> {
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,
Expand Down
Loading