From 4f7cd7fb20d3d56e1d10bb9c02f445e3b4dda0c2 Mon Sep 17 00:00:00 2001 From: pashpashpash Date: Wed, 22 Jan 2025 15:55:23 -0800 Subject: [PATCH] prettier fix --- src/core/webview/ClineProvider.ts | 25 ++- src/extension.ts | 12 +- src/services/auth/FirebaseAuthManager.ts | 168 +++++++++--------- src/services/auth/config.ts | 16 +- src/shared/ExtensionMessage.ts | 9 +- .../src/components/account/AccountView.tsx | 4 +- 6 files changed, 119 insertions(+), 115 deletions(-) diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index a2bf790720..927b361094 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -28,7 +28,6 @@ import { AutoApprovalSettings, DEFAULT_AUTO_APPROVAL_SETTINGS } from "../../shar import { BrowserSettings, DEFAULT_BROWSER_SETTINGS } from "../../shared/BrowserSettings" import { ChatSettings, DEFAULT_CHAT_SETTINGS } from "../../shared/ChatSettings" - /* https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts @@ -147,11 +146,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { await this.storeSecret("authToken", token) } - async setUserInfo(info?: { - displayName: string | null - email: string | null - photoURL: string | null - }) { + async setUserInfo(info?: { displayName: string | null; email: string | null; photoURL: string | null }) { await this.updateGlobalState("userInfo", info) } @@ -627,17 +622,19 @@ export class ClineProvider implements vscode.WebviewViewProvider { break case "accountLoginClicked": { // Generate nonce for state validation - const nonce = crypto.randomBytes(32).toString('hex') - await this.storeSecret('authNonce', nonce) - + const nonce = crypto.randomBytes(32).toString("hex") + await this.storeSecret("authNonce", nonce) + // Open browser for authentication with state param console.log("Login button clicked in account page") console.log("Opening auth page with state param") - const uriScheme = vscode.env.uriScheme; + const uriScheme = vscode.env.uriScheme - const authUrl = vscode.Uri.parse(`https://app.cline.bot/auth?state=${encodeURIComponent(nonce)}&callback_url=${encodeURIComponent(`${uriScheme || "vscode"}://saoudrizwan.claude-dev/auth`)}`); - vscode.env.openExternal(authUrl); + const authUrl = vscode.Uri.parse( + `https://app.cline.bot/auth?state=${encodeURIComponent(nonce)}&callback_url=${encodeURIComponent(`${uriScheme || "vscode"}://saoudrizwan.claude-dev/auth`)}`, + ) + vscode.env.openExternal(authUrl) break } case "accountLogoutClicked": { @@ -805,7 +802,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { try { // First sign in with Firebase to trigger auth state change await this.authManager.signInWithCustomToken(token) - + // Then store the token securely await this.storeSecret("authToken", token) await this.postStateToWebview() @@ -1091,7 +1088,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { chatSettings, userInfo, } = await this.getState() - + const authToken = await this.getSecret("authToken") return { version: this.context.extension?.packageJSON?.version ?? "", diff --git a/src/extension.ts b/src/extension.ts index 1f5164686f..1faee0133b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -138,9 +138,9 @@ export function activate(context: vscode.ExtensionContext) { console.log("URI Handler called with:", { path: uri.path, query: uri.query, - scheme: uri.scheme + scheme: uri.scheme, }) - + const path = uri.path const query = new URLSearchParams(uri.query.replace(/\+/g, "%2B")) const visibleProvider = ClineProvider.getVisibleInstance() @@ -158,18 +158,18 @@ export function activate(context: vscode.ExtensionContext) { case "/auth": { const token = query.get("token") const state = query.get("state") - + console.log("Auth callback received:", { token: token, state: state, }) - + // Validate state parameter - if (!await visibleProvider.validateAuthState(state)) { + if (!(await visibleProvider.validateAuthState(state))) { vscode.window.showErrorMessage("Invalid auth state") return } - + if (token) { await visibleProvider.handleAuthCallback(token) } diff --git a/src/services/auth/FirebaseAuthManager.ts b/src/services/auth/FirebaseAuthManager.ts index 9a53458606..835a84c0c0 100644 --- a/src/services/auth/FirebaseAuthManager.ts +++ b/src/services/auth/FirebaseAuthManager.ts @@ -1,99 +1,99 @@ -import { initializeApp } from "firebase/app"; -import { Auth, User, getAuth, onAuthStateChanged, signInWithCustomToken, signOut } from "firebase/auth"; -import * as vscode from "vscode"; -import { ClineProvider } from "../../core/webview/ClineProvider"; -import { firebaseConfig } from "./config"; +import { initializeApp } from "firebase/app" +import { Auth, User, getAuth, onAuthStateChanged, signInWithCustomToken, signOut } from "firebase/auth" +import * as vscode from "vscode" +import { ClineProvider } from "../../core/webview/ClineProvider" +import { firebaseConfig } from "./config" export interface UserInfo { - displayName: string | null; - email: string | null; - photoURL: string | null; + displayName: string | null + email: string | null + photoURL: string | null } export class FirebaseAuthManager { - private providerRef: WeakRef; - private auth: Auth; - private disposables: vscode.Disposable[] = []; + private providerRef: WeakRef + private auth: Auth + private disposables: vscode.Disposable[] = [] - constructor(provider: ClineProvider) { - console.log("Initializing FirebaseAuthManager", { provider }); - this.providerRef = new WeakRef(provider); - const app = initializeApp(firebaseConfig); - this.auth = getAuth(app); - console.log("Firebase app initialized", { appConfig: firebaseConfig }); + constructor(provider: ClineProvider) { + console.log("Initializing FirebaseAuthManager", { provider }) + this.providerRef = new WeakRef(provider) + const app = initializeApp(firebaseConfig) + this.auth = getAuth(app) + console.log("Firebase app initialized", { appConfig: firebaseConfig }) - // Auth state listener - onAuthStateChanged(this.auth, this.handleAuthStateChange.bind(this)); - console.log("Auth state change listener added"); + // Auth state listener + onAuthStateChanged(this.auth, this.handleAuthStateChange.bind(this)) + console.log("Auth state change listener added") - // Try to restore session - this.restoreSession(); - } + // Try to restore session + this.restoreSession() + } - private async restoreSession() { - console.log("Attempting to restore session"); - const provider = this.providerRef.deref(); - if (!provider) { - console.log("Provider reference lost during session restore"); - return; - } - - const storedToken = await provider.getSecret("authToken"); - if (storedToken) { - console.log("Found stored auth token, attempting to restore session"); - try { - await this.signInWithCustomToken(storedToken); - console.log("Session restored successfully"); - } catch (error) { - console.error("Failed to restore session, clearing token:", error); - await provider.setAuthToken(undefined); - await provider.setUserInfo(undefined); - } - } else { - console.log("No stored auth token found"); - } - } + private async restoreSession() { + console.log("Attempting to restore session") + const provider = this.providerRef.deref() + if (!provider) { + console.log("Provider reference lost during session restore") + return + } - private async handleAuthStateChange(user: User | null) { - console.log("Auth state changed", { user }); - const provider = this.providerRef.deref(); - if (!provider) { - console.log("Provider reference lost"); - return; - } + const storedToken = await provider.getSecret("authToken") + if (storedToken) { + console.log("Found stored auth token, attempting to restore session") + try { + await this.signInWithCustomToken(storedToken) + console.log("Session restored successfully") + } catch (error) { + console.error("Failed to restore session, clearing token:", error) + await provider.setAuthToken(undefined) + await provider.setUserInfo(undefined) + } + } else { + console.log("No stored auth token found") + } + } - if (user) { - console.log("User signed in", { userId: user.uid }); - const idToken = await user.getIdToken(); - await provider.setAuthToken(idToken); - // Store public user info in state - await provider.setUserInfo({ - displayName: user.displayName, - email: user.email, - photoURL: user.photoURL - }); - console.log("User info set in provider", { user }); - } else { - console.log("User signed out"); - await provider.setAuthToken(undefined); - await provider.setUserInfo(undefined); - } - await provider.postStateToWebview(); - console.log("Webview state updated"); - } + private async handleAuthStateChange(user: User | null) { + console.log("Auth state changed", { user }) + const provider = this.providerRef.deref() + if (!provider) { + console.log("Provider reference lost") + return + } - async signInWithCustomToken(token: string) { - console.log("Signing in with custom token", { token }); - await signInWithCustomToken(this.auth, token); - } + if (user) { + console.log("User signed in", { userId: user.uid }) + const idToken = await user.getIdToken() + await provider.setAuthToken(idToken) + // Store public user info in state + await provider.setUserInfo({ + displayName: user.displayName, + email: user.email, + photoURL: user.photoURL, + }) + console.log("User info set in provider", { user }) + } else { + console.log("User signed out") + await provider.setAuthToken(undefined) + await provider.setUserInfo(undefined) + } + await provider.postStateToWebview() + console.log("Webview state updated") + } - async signOut() { - console.log("Signing out"); - await signOut(this.auth); - } + async signInWithCustomToken(token: string) { + console.log("Signing in with custom token", { token }) + await signInWithCustomToken(this.auth, token) + } - dispose() { - this.disposables.forEach(d => d.dispose()); - console.log("Disposables disposed", { count: this.disposables.length }); - } + async signOut() { + console.log("Signing out") + await signOut(this.auth) + } + + dispose() { + this.disposables.forEach((d) => d.dispose()) + console.log("Disposables disposed", { count: this.disposables.length }) + } } diff --git a/src/services/auth/config.ts b/src/services/auth/config.ts index 7348d1e192..86034075a2 100644 --- a/src/services/auth/config.ts +++ b/src/services/auth/config.ts @@ -1,10 +1,10 @@ // Public Firebase config (safe for open source) export const firebaseConfig = { - apiKey: "AIzaSyDcXAaanNgR2_T0dq2oOl5XyKPksYHppVo", - authDomain: "cline-bot.firebaseapp.com", - projectId: "cline-bot", - storageBucket: "cline-bot.firebasestorage.app", - messagingSenderId: "364369702101", - appId: "1:364369702101:web:0013885dcf20b43799c65c", - measurementId: "G-MDPRELSCD1" -}; \ No newline at end of file + apiKey: "AIzaSyDcXAaanNgR2_T0dq2oOl5XyKPksYHppVo", + authDomain: "cline-bot.firebaseapp.com", + projectId: "cline-bot", + storageBucket: "cline-bot.firebasestorage.app", + messagingSenderId: "364369702101", + appId: "1:364369702101:web:0013885dcf20b43799c65c", + measurementId: "G-MDPRELSCD1", +} diff --git a/src/shared/ExtensionMessage.ts b/src/shared/ExtensionMessage.ts index 4d7eaa6021..490e06599a 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -25,7 +25,14 @@ export interface ExtensionMessage { | "vsCodeLmModels" | "requestVsCodeLmModels" text?: string - action?: "chatButtonClicked" | "mcpButtonClicked" | "settingsButtonClicked" | "historyButtonClicked" | "didBecomeVisible" | "accountLoginClicked" | "accountLogoutClicked" + action?: + | "chatButtonClicked" + | "mcpButtonClicked" + | "settingsButtonClicked" + | "historyButtonClicked" + | "didBecomeVisible" + | "accountLoginClicked" + | "accountLogoutClicked" invoke?: "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" state?: ExtensionState images?: string[] diff --git a/webview-ui/src/components/account/AccountView.tsx b/webview-ui/src/components/account/AccountView.tsx index 6c5473d6a3..d4d9ec5fb9 100644 --- a/webview-ui/src/components/account/AccountView.tsx +++ b/webview-ui/src/components/account/AccountView.tsx @@ -54,14 +54,14 @@ const AccountView = ({ onDone }: AccountViewProps) => { {isLoggedIn ? ( <> {userInfo?.photoURL && ( - Profile )}