Skip to content

Commit b9253d0

Browse files
authored
Support basic auth in opencode sdk (#4697)
1 parent 2458e75 commit b9253d0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/sdk/js/src/client.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ export function createOpencodeClient(config?: Config & { directory?: string }) {
2424
}
2525
}
2626

27+
if (config?.baseUrl) {
28+
const baseUrl = new URL(config.baseUrl)
29+
if (baseUrl.username || baseUrl.password) {
30+
config.headers = {
31+
...config.headers,
32+
Authorization: `Basic ${btoa(`${baseUrl.username}:${baseUrl.password}`)}`,
33+
}
34+
baseUrl.username = ""
35+
baseUrl.password = ""
36+
config.baseUrl = baseUrl.toString()
37+
}
38+
}
39+
2740
const client = createClient(config)
2841
return new OpencodeClient({ client })
2942
}

0 commit comments

Comments
 (0)