Skip to content

Commit

Permalink
[Backport jb-v7.5.x] fix/accounts: Do not sign out when removing an u…
Browse files Browse the repository at this point in the history
…nrelated account (#6270)

Fixes QA-194.

## Test plan

Manual test:
- Sign in to JetBrains with two accounts.
- Switch to the Accounts tab, Switch Accounts and remove the second
account.
- Verify that you stay signed in on the accounts tab, and the second
account is gone from the account switcher.

## Changelog

fix/accounts: Removing a second account does not dump you back at the
login screen. <br> Backport 7cc7953
from #6269

Co-authored-by: Dominic Cooney <[email protected]>
  • Loading branch information
sourcegraph-release-bot and dominiccooney authored Dec 6, 2024
1 parent 021cd4a commit b8eac05
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion vscode/src/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export async function signOut(endpoint: string): Promise<void> {

await Promise.all([secretStorage.deleteToken(endpoint), localStorage.deleteEndpoint(endpoint)])

authProvider.signout()
authProvider.signout(endpoint)
}

/**
Expand Down
3 changes: 3 additions & 0 deletions vscode/src/chat/chat-view/ChatController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
} else {
await showSignOutMenu()
}
// Send config to refresh the endpoint history list.
// TODO: Remove this when the config for webview is observable, see getConfigForWebview.
await this.sendConfig(currentAuthStatus())
break
}
if (message.authKind === 'switch') {
Expand Down
7 changes: 6 additions & 1 deletion vscode/src/services/AuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class AuthProvider implements vscode.Disposable {
*/
private lastValidatedAndStoredCredentials =
new Subject<ResolvedConfigurationCredentialsOnly | null>()
private lastEndpoint: string | undefined

private hasAuthed = false

Expand Down Expand Up @@ -113,6 +114,7 @@ class AuthProvider implements vscode.Disposable {
this.subscriptions.push(
authStatus.subscribe(authStatus => {
try {
this.lastEndpoint = authStatus.endpoint
vscode.commands.executeCommand(
'setContext',
'cody.activated',
Expand Down Expand Up @@ -167,7 +169,10 @@ class AuthProvider implements vscode.Disposable {
this.refreshRequests.next()
}

public signout(): void {
public signout(endpoint: string): void {
if (this.lastEndpoint !== endpoint) {
return
}
this.lastValidatedAndStoredCredentials.next(null)
this.status.next({
authenticated: false,
Expand Down
8 changes: 4 additions & 4 deletions vscode/webviews/components/AccountSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const AccountSwitcher: React.FC<AccountSwitcherProps> = ({
setLoading,
}) => {
type PopoverView = 'switch' | 'remove' | 'add'
const [getPopoverView, serPopoverView] = useState<PopoverView>('switch')
const [getPopoverView, setPopoverView] = useState<PopoverView>('switch')
const [isOpen, setIsOpen] = useState(false)

const [endpointToRemove, setEndpointToRemove] = useState<string | null>(null)
Expand All @@ -47,7 +47,7 @@ export const AccountSwitcher: React.FC<AccountSwitcherProps> = ({
setIsOpen(open)
if (!open) {
setEndpointToRemove(null)
serPopoverView('switch')
setPopoverView('switch')
setAddFormData(() => ({
endpoint: 'https://',
accessToken: '',
Expand Down Expand Up @@ -79,7 +79,7 @@ export const AccountSwitcher: React.FC<AccountSwitcherProps> = ({
variant="ghost"
onClick={() => {
setEndpointToRemove(endpoint)
serPopoverView('remove')
setPopoverView('remove')
}}
>
<CircleMinus size={16} />
Expand All @@ -102,7 +102,7 @@ export const AccountSwitcher: React.FC<AccountSwitcherProps> = ({
key={'add-account'}
variant="ghost"
onClick={() => {
serPopoverView('add')
setPopoverView('add')
}}
>
<Plus size={16} />
Expand Down

0 comments on commit b8eac05

Please sign in to comment.