mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-05 08:10:14 +00:00
prettier fix
This commit is contained in:
parent
7deb753165
commit
4f7cd7fb20
6 changed files with 119 additions and 115 deletions
|
|
@ -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 ?? "",
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ClineProvider>;
|
||||
private auth: Auth;
|
||||
private disposables: vscode.Disposable[] = [];
|
||||
private providerRef: WeakRef<ClineProvider>
|
||||
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 })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
};
|
||||
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",
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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[]
|
||||
|
|
|
|||
|
|
@ -54,14 +54,14 @@ const AccountView = ({ onDone }: AccountViewProps) => {
|
|||
{isLoggedIn ? (
|
||||
<>
|
||||
{userInfo?.photoURL && (
|
||||
<img
|
||||
<img
|
||||
src={userInfo.photoURL}
|
||||
alt="Profile"
|
||||
style={{
|
||||
width: 48,
|
||||
height: 48,
|
||||
borderRadius: "50%",
|
||||
marginBottom: 10
|
||||
marginBottom: 10,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue