-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathhandleUri.ts
More file actions
66 lines (62 loc) · 2.29 KB
/
Copy pathhandleUri.ts
File metadata and controls
66 lines (62 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import * as vscode from "vscode"
import { getRouterUnavailableSignInMessage } from "../core/config/routerRemoval"
import { ClineProvider } from "../core/webview/ClineProvider"
import { handleAuthCallback as handleZooCodeAuthCallback, setZooCodeUserInfo } from "../services/zoo-code-auth"
export const handleUri = async (uri: vscode.Uri) => {
const path = uri.path
const query = new URLSearchParams(uri.query.replace(/\+/g, "%2B"))
const visibleProvider = ClineProvider.getVisibleInstance()
switch (path) {
case "/openrouter": {
if (!visibleProvider) return
const code = query.get("code")
if (code) {
await visibleProvider.handleOpenRouterCallback(code)
}
break
}
case "/requesty": {
if (!visibleProvider) return
const code = query.get("code")
const baseUrl = query.get("baseUrl")
if (code) {
await visibleProvider.handleRequestyCallback(code, baseUrl)
}
break
}
case "/auth/clerk/callback": {
vscode.window.showInformationMessage(getRouterUnavailableSignInMessage())
break
}
case "/auth-callback": {
const token = query.get("token")
if (token) {
// Extract user info from callback URL params
// URLSearchParams.get() already decodes percent-encoded values - no need for decodeURIComponent
// Use null (not undefined) for missing values to actively clear stale data
const name = query.get("name") ?? null
const email = query.get("email") ?? null
const image = query.get("image") ?? null
const success = await handleZooCodeAuthCallback(token)
if (success) {
// Store user info after successful auth validation (regardless of webview visibility)
// Always call setZooCodeUserInfo to clear stale data when fields are missing
await setZooCodeUserInfo({
name,
email,
image,
})
// Write the token to all active provider instances regardless of visibility.
// The profile settings write (handleZooCodeCallback) must run on any active
// instance — not just the visible one — so the zoo-gateway zooSessionToken
// is persisted even when the sidebar/panel is hidden at callback time.
const allInstances = ClineProvider.getAllInstances()
await Promise.all(allInstances.map((instance) => instance.handleZooCodeCallback(token)))
}
}
break
}
default:
break
}
}