mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
fix: ensure Auth.all returns valid objs (#5128)
This commit is contained in:
parent
af1080dd42
commit
725f658260
2 changed files with 10 additions and 7 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue