11import path from "path"
22import { Global } from "../global"
33import z from "zod"
4+ import { Filesystem } from "../util/filesystem"
45
56export const OAUTH_DUMMY_KEY = "opencode-oauth-dummy-key"
67
@@ -42,8 +43,7 @@ export namespace Auth {
4243 }
4344
4445 export async function all ( ) : Promise < Record < string , Info > > {
45- const file = Bun . file ( filepath )
46- const data = await file . json ( ) . catch ( ( ) => ( { } ) as Record < string , unknown > )
46+ const data = await Filesystem . readJson < Record < string , unknown > > ( filepath ) . catch ( ( ) => ( { } ) )
4747 return Object . entries ( data ) . reduce (
4848 ( acc , [ key , value ] ) => {
4949 const parsed = Info . safeParse ( value )
@@ -56,15 +56,13 @@ export namespace Auth {
5656 }
5757
5858 export async function set ( key : string , info : Info ) {
59- const file = Bun . file ( filepath )
6059 const data = await all ( )
61- await Bun . write ( file , JSON . stringify ( { ...data , [ key ] : info } , null , 2 ) , { mode : 0o600 } )
60+ await Filesystem . writeJson ( filepath , { ...data , [ key ] : info } , 0o600 )
6261 }
6362
6463 export async function remove ( key : string ) {
65- const file = Bun . file ( filepath )
6664 const data = await all ( )
6765 delete data [ key ]
68- await Bun . write ( file , JSON . stringify ( data , null , 2 ) , { mode : 0o600 } )
66+ await Filesystem . writeJson ( filepath , data , 0o600 )
6967 }
7068}
0 commit comments