|
|
@@ -6,7 +6,7 @@ import fs from "fs/promises"
|
|
|
export namespace AuthAnthropic {
|
|
|
const CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e"
|
|
|
|
|
|
- const file = Bun.file(path.join(Global.Path.data, "auth", "anthropic.json"))
|
|
|
+ const filepath = path.join(Global.Path.data, "auth", "anthropic.json")
|
|
|
|
|
|
export async function authorize() {
|
|
|
const pkce = await generatePKCE()
|
|
|
@@ -48,15 +48,15 @@ export namespace AuthAnthropic {
|
|
|
}),
|
|
|
})
|
|
|
if (!result.ok) throw new ExchangeFailed()
|
|
|
+ const file = Bun.file(filepath)
|
|
|
await Bun.write(file, result)
|
|
|
await fs.chmod(file.name!, 0o600)
|
|
|
}
|
|
|
|
|
|
- export const exists = file.exists
|
|
|
-
|
|
|
export async function access() {
|
|
|
- if (!(await file.exists())) return
|
|
|
- const result = await file.json()
|
|
|
+ const file = Bun.file(filepath)
|
|
|
+ const result = await file.json().catch(() => ({}))
|
|
|
+ if (!result) return
|
|
|
const refresh = result.refresh_token
|
|
|
const response = await fetch(
|
|
|
"https://console.anthropic.com/v1/oauth/token",
|