Skip to content

Commit 725f658

Browse files
authored
fix: ensure Auth.all returns valid objs (sst#5128)
1 parent af1080d commit 725f658

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

packages/opencode/src/auth/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,19 @@ export namespace Auth {
3535
const filepath = path.join(Global.Path.data, "auth.json")
3636

3737
export async function get(providerID: string) {
38-
const file = Bun.file(filepath)
39-
return file
40-
.json()
41-
.catch(() => ({}))
42-
.then((x) => x[providerID] as Info | undefined)
38+
const auth = await all()
39+
return auth[providerID]
4340
}
4441

4542
export async function all(): Promise<Record<string, Info>> {
4643
const file = Bun.file(filepath)
47-
return file.json().catch(() => ({}))
44+
const data = await file.json().catch(() => ({} as Record<string, unknown>))
45+
return Object.entries(data).reduce((acc, [key, value]) => {
46+
const parsed = Info.safeParse(value)
47+
if (!parsed.success) return acc
48+
acc[key] = parsed.data
49+
return acc
50+
}, {} as Record<string, Info>)
4851
}
4952

5053
export async function set(key: string, info: Info) {

packages/opencode/src/cli/cmd/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const AuthListCommand = cmd({
2929
const homedir = os.homedir()
3030
const displayPath = authPath.startsWith(homedir) ? authPath.replace(homedir, "~") : authPath
3131
prompts.intro(`Credentials ${UI.Style.TEXT_DIM}${displayPath}`)
32-
const results = await Auth.all().then((x) => Object.entries(x))
32+
const results = Object.entries(await Auth.all())
3333
const database = await ModelsDev.get()
3434

3535
for (const [providerID, result] of results) {

0 commit comments

Comments
 (0)