Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/accounts: Do not sign out when removing an unrelated account #6269

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
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
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 @@ -477,6 +477,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
Loading