Skip to content

Fix Connect Cloud credential selection when there are multiple accounts#3446

Open
mslynch wants to merge 2 commits intomainfrom
pcc-multi-account-fix
Open

Fix Connect Cloud credential selection when there are multiple accounts#3446
mslynch wants to merge 2 commits intomainfrom
pcc-multi-account-fix

Conversation

@mslynch
Copy link
Member

@mslynch mslynch commented Feb 4, 2026

Intent

Account selection is broken when there are multiple PCC accounts - when the user selects an account, no credential is created, and instead this is logged:

[Extension Host] User has dismissed the New Credential flow. Exiting. (at console.<anonymous> (file:///Applications/Positron.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:96148:14))

The bug was introduced here: https://github.com/posit-dev/publisher/pull/3303/changes#diff-85757b4df2fd959fdb90483f09e44e9c37757ff9cf7995217245e569f6680e29

Type of Change

    • Bug Fix
    • New Feature
    • Breaking Change
    • Documentation
    • Refactor
    • Tooling

Approach

Fix the condition checking for account - We needed to check if the account from .find is present. The actual happy path was removed and only the fallback case was handled.

User Impact

Allows users who have multiple accounts to be able to create credentials again.

Automated Tests

No established pattern for unit tests in this area of the code.

Directions for Reviewers

Set up access on your Connect Cloud user to have access to multiple accounts to be able to publish to, then try to add a credential for one of them.

Checklist

  • I have updated the root CHANGELOG.md to cover notable changes.

(!account?.id || !account?.name || !account?.displayName) &&
accounts[0]
) {
if (account?.id && account?.name && account?.displayName) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to check each field individually here instead of just checking for a non-nullish account object?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just check for the object like: if (account) { ... }, in fact I would write this code this way so there is always a fallback and no else if statement is needed:

// fallback to the first publishable account if the selected account is ever not found
const account = accounts.find((a) => a.displayName === pick.label) || accounts[0];
if (account) {
  state.data.accountId = account.id;
  state.data.accountName = account.name;
  state.data.displayName = account.displayName;
}

@mslynch mslynch marked this pull request as ready for review February 4, 2026 16:09
@mslynch mslynch requested a review from a team as a code owner February 4, 2026 16:09
@mslynch mslynch requested review from rodriin and tyatposit February 4, 2026 16:10
Copy link
Collaborator

@rodriin rodriin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, I suggested a small code change.

(!account?.id || !account?.name || !account?.displayName) &&
accounts[0]
) {
if (account?.id && account?.name && account?.displayName) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just check for the object like: if (account) { ... }, in fact I would write this code this way so there is always a fallback and no else if statement is needed:

// fallback to the first publishable account if the selected account is ever not found
const account = accounts.find((a) => a.displayName === pick.label) || accounts[0];
if (account) {
  state.data.accountId = account.id;
  state.data.accountName = account.name;
  state.data.displayName = account.displayName;
}

Copy link
Collaborator

@tyatposit tyatposit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a unit test to try to catch this should something like it happen again?

@dotNomad
Copy link
Collaborator

dotNomad commented Feb 6, 2026

Marking this as a fix for #3440

@dotNomad dotNomad linked an issue Feb 6, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to store credential or publish to Connect Cloud

4 participants