Skip to content

Commit c970274

Browse files
authored
Disconnect extension bridge on logout (RooCodeInc#7563)
* Disconnect extension bridge on logout * Remove bad test * Cleanup
1 parent 63b71d8 commit c970274

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

packages/cloud/src/bridge/BridgeOrchestrator.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,19 @@ export class BridgeOrchestrator {
6161
public static async connectOrDisconnect(
6262
userInfo: CloudUserInfo | null,
6363
remoteControlEnabled: boolean | undefined,
64-
options: BridgeOrchestratorOptions,
64+
options?: BridgeOrchestratorOptions,
6565
): Promise<void> {
6666
const isEnabled = BridgeOrchestrator.isEnabled(userInfo, remoteControlEnabled)
6767
const instance = BridgeOrchestrator.instance
6868

6969
if (isEnabled) {
7070
if (!instance) {
71+
if (!options) {
72+
console.error(
73+
`[BridgeOrchestrator#connectOrDisconnect] Cannot connect: options are required for connection`,
74+
)
75+
return
76+
}
7177
try {
7278
console.log(`[BridgeOrchestrator#connectOrDisconnect] Connecting...`)
7379
BridgeOrchestrator.instance = new BridgeOrchestrator(options)

src/extension.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ try {
1212
console.warn("Failed to load environment variables:", e)
1313
}
1414

15-
import type { CloudUserInfo } from "@roo-code/types"
15+
import type { CloudUserInfo, AuthState } from "@roo-code/types"
1616
import { CloudService, BridgeOrchestrator } from "@roo-code/cloud"
1717
import { TelemetryService, PostHogTelemetryClient } from "@roo-code/telemetry"
1818

@@ -53,7 +53,7 @@ let outputChannel: vscode.OutputChannel
5353
let extensionContext: vscode.ExtensionContext
5454
let cloudService: CloudService | undefined
5555

56-
let authStateChangedHandler: (() => void) | undefined
56+
let authStateChangedHandler: ((data: { state: AuthState; previousState: AuthState }) => Promise<void>) | undefined
5757
let settingsUpdatedHandler: (() => void) | undefined
5858
let userInfoHandler: ((data: { userInfo: CloudUserInfo }) => Promise<void>) | undefined
5959

@@ -127,7 +127,28 @@ export async function activate(context: vscode.ExtensionContext) {
127127

128128
// Initialize Roo Code Cloud service.
129129
const postStateListener = () => ClineProvider.getVisibleInstance()?.postStateToWebview()
130-
authStateChangedHandler = postStateListener
130+
131+
authStateChangedHandler = async (data: { state: AuthState; previousState: AuthState }) => {
132+
postStateListener()
133+
134+
// Check if user has logged out
135+
if (data.state === "logged-out") {
136+
try {
137+
// Disconnect the bridge when user logs out
138+
// When userInfo is null and remoteControlEnabled is false, BridgeOrchestrator
139+
// will disconnect. The options parameter is not needed for disconnection.
140+
await BridgeOrchestrator.connectOrDisconnect(null, false)
141+
142+
cloudLogger("[CloudService] BridgeOrchestrator disconnected on logout")
143+
} catch (error) {
144+
cloudLogger(
145+
`[CloudService] Failed to disconnect BridgeOrchestrator on logout: ${
146+
error instanceof Error ? error.message : String(error)
147+
}`,
148+
)
149+
}
150+
}
151+
}
131152

132153
settingsUpdatedHandler = async () => {
133154
const userInfo = CloudService.instance.getUserInfo()

0 commit comments

Comments
 (0)