Skip to content

Commit e05cd8c

Browse files
authored
Fix firebase session being inconsistent in popout tabs (RooCodeInc#2608)
* Fix firebase session being inconsistent in popout tabs * Create rude-vans-cry.md
1 parent e2458b2 commit e05cd8c

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

.changeset/rude-vans-cry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
Fix issue with Cline accounts not showing user info in popout tabs

src/core/controller/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export class Controller {
107107
async handleSignOut() {
108108
try {
109109
await storeSecret(this.context, "clineApiKey", undefined)
110+
await updateGlobalState(this.context, "userInfo", undefined)
110111
await updateGlobalState(this.context, "apiProvider", "openrouter")
111112
await this.postStateToWebview()
112113
vscode.window.showInformationMessage("Successfully logged out of Cline")

webview-ui/src/components/account/AccountView.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ClineLogoWhite from "../../assets/ClineLogoWhite"
77
import CountUp from "react-countup"
88
import CreditsHistoryTable from "./CreditsHistoryTable"
99
import { UsageTransaction, PaymentTransaction } from "../../../../src/shared/ClineAccount"
10+
import { useExtensionState } from "../../context/ExtensionStateContext"
1011

1112
type AccountViewProps = {
1213
onDone: () => void
@@ -29,7 +30,11 @@ const AccountView = ({ onDone }: AccountViewProps) => {
2930
}
3031

3132
export const ClineAccountView = () => {
32-
const { user, handleSignOut } = useFirebaseAuth()
33+
const { user: firebaseUser, handleSignOut } = useFirebaseAuth()
34+
const { userInfo, apiConfiguration } = useExtensionState()
35+
36+
let user = apiConfiguration?.clineApiKey ? firebaseUser || userInfo : undefined
37+
3338
const [balance, setBalance] = useState(0)
3439
const [isLoading, setIsLoading] = useState(true)
3540
const [usageData, setUsageData] = useState<UsageTransaction[]>([])

webview-ui/src/components/settings/ClineAccountInfoCard.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { VSCodeButton } from "@vscode/webview-ui-toolkit/react"
22
import { useFirebaseAuth } from "../../context/FirebaseAuthContext"
33
import { vscode } from "../../utils/vscode"
4+
import { useExtensionState } from "../../context/ExtensionStateContext"
45

56
export const ClineAccountInfoCard = () => {
6-
const { user, handleSignOut } = useFirebaseAuth()
7+
const { user: firebaseUser, handleSignOut } = useFirebaseAuth()
8+
const { userInfo, apiConfiguration } = useExtensionState()
9+
10+
let user = apiConfiguration?.clineApiKey ? firebaseUser || userInfo : undefined
711

812
const handleLogin = () => {
913
vscode.postMessage({ type: "accountLoginClicked" })

webview-ui/src/context/FirebaseAuthContext.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ export const FirebaseAuthProvider: React.FC<{ children: React.ReactNode }> = ({
3737
setUser(user)
3838
setIsInitialized(true)
3939

40+
console.log("onAuthStateChanged user", user)
41+
42+
if (!user) {
43+
// when opening the extension in a new webview (ie if you logged in to sidebar webview but then open a popout tab webview) this effect will trigger without the original webview's session, resulting in us clearing out the user info object.
44+
// we rely on this object to determine if the user is logged in, so we only want to clear it when the user logs out, rather than whenever a webview without a session is opened.
45+
return
46+
}
4047
// Sync auth state with extension
4148
vscode.postMessage({
4249
type: "authStateChanged",

0 commit comments

Comments
 (0)