summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorry2009 <[email protected]>2025-12-07 23:22:21 -0500
committerGitHub <[email protected]>2025-12-07 22:22:21 -0600
commit725f6582603148ed44357459c378259bd8249275 (patch)
tree3cbfdebf682fe305b9ffc3bee11234a7cdbba500
parentaf1080dd42f41f79cc3df5d00c45fc2f472f3612 (diff)
downloadopencode-725f6582603148ed44357459c378259bd8249275.tar.gz
opencode-725f6582603148ed44357459c378259bd8249275.zip
fix: ensure Auth.all returns valid objs (#5128)
-rw-r--r--packages/opencode/src/auth/index.ts15
-rw-r--r--packages/opencode/src/cli/cmd/auth.ts2
2 files changed, 10 insertions, 7 deletions
diff --git a/packages/opencode/src/auth/index.ts b/packages/opencode/src/auth/index.ts
index 883b9acc6..e6adb77cf 100644
--- a/packages/opencode/src/auth/index.ts
+++ b/packages/opencode/src/auth/index.ts
@@ -35,16 +35,19 @@ export namespace Auth {
const filepath = path.join(Global.Path.data, "auth.json")
export async function get(providerID: string) {
- const file = Bun.file(filepath)
- return file
- .json()
- .catch(() => ({}))
- .then((x) => x[providerID] as Info | undefined)
+ const auth = await all()
+ return auth[providerID]
}
export async function all(): Promise<Record<string, Info>> {
const file = Bun.file(filepath)
- return file.json().catch(() => ({}))
+ const data = await file.json().catch(() => ({} as Record<string, unknown>))
+ return Object.entries(data).reduce((acc, [key, value]) => {
+ const parsed = Info.safeParse(value)
+ if (!parsed.success) return acc
+ acc[key] = parsed.data
+ return acc
+ }, {} as Record<string, Info>)
}
export async function set(key: string, info: Info) {
diff --git a/packages/opencode/src/cli/cmd/auth.ts b/packages/opencode/src/cli/cmd/auth.ts
index 1f37ec805..af4424e24 100644
--- a/packages/opencode/src/cli/cmd/auth.ts
+++ b/packages/opencode/src/cli/cmd/auth.ts
@@ -29,7 +29,7 @@ export const AuthListCommand = cmd({
const homedir = os.homedir()
const displayPath = authPath.startsWith(homedir) ? authPath.replace(homedir, "~") : authPath
prompts.intro(`Credentials ${UI.Style.TEXT_DIM}${displayPath}`)
- const results = await Auth.all().then((x) => Object.entries(x))
+ const results = Object.entries(await Auth.all())
const database = await ModelsDev.get()
for (const [providerID, result] of results) {