mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-08-31 01:37:28 +08:00
fix(share): skip session sync when kilo token is invalid
Validate the kilo API token against the user endpoint before syncing and cache auth validity per token to avoid repeated checks.
This commit is contained in:
@@ -16,6 +16,23 @@ import type * as SDK from "@kilocode/sdk/v2" // kilocode_change
|
||||
export namespace ShareNext {
|
||||
const log = Log.create({ service: "share-next" })
|
||||
|
||||
const authCache = new Map<string, { valid: boolean }>()
|
||||
|
||||
async function authValid(token: string) {
|
||||
const cached = authCache.get(token)
|
||||
if (cached) return cached.valid
|
||||
|
||||
const response = await fetch("https://app.kilo.ai/api/user", {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}).catch(() => undefined)
|
||||
|
||||
const valid = response ? response.ok : false
|
||||
authCache.set(token, { valid: !!response?.ok })
|
||||
return valid
|
||||
}
|
||||
|
||||
export async function kilocodeToken() {
|
||||
const auth = await Auth.get("kilo")
|
||||
if (auth?.type === "api" && auth.key.length > 0) return auth.key
|
||||
@@ -34,6 +51,9 @@ export namespace ShareNext {
|
||||
const token = await kilocodeToken()
|
||||
if (!token) return undefined
|
||||
|
||||
const valid = await authValid(token)
|
||||
if (!valid) return undefined
|
||||
|
||||
const base = await Config.get().then((x) => x.enterprise?.url ?? "https://ingest.kilosessions.ai")
|
||||
const baseHeaders: Record<string, string> = {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
Reference in New Issue
Block a user