From f403623704c2e397e2274dd9d82c470f4fa766fb Mon Sep 17 00:00:00 2001 From: Ben Davis Date: Fri, 27 Feb 2026 21:06:19 -0800 Subject: [PATCH] fix(auth): handle empty auth state and align provider auth docs --- apps/cli/src/lib/copilot-oauth.ts | 4 +++- apps/cli/src/lib/opencode-oauth.ts | 4 +++- apps/docs/btca.spec.md | 5 +++-- apps/docs/guides/authentication.mdx | 2 +- apps/server/README.md | 4 ++-- apps/server/src/providers/auth.ts | 10 +++++++--- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/cli/src/lib/copilot-oauth.ts b/apps/cli/src/lib/copilot-oauth.ts index 1f335969..fd778c93 100644 --- a/apps/cli/src/lib/copilot-oauth.ts +++ b/apps/cli/src/lib/copilot-oauth.ts @@ -41,7 +41,9 @@ const readAuthFile = async () => { const file = Bun.file(filepath); if (!(await file.exists())) return {}; try { - const content = await file.json(); + const text = await file.text(); + if (text.trim().length === 0) return {}; + const content = JSON.parse(text) as unknown; return content && typeof content === 'object' ? (content as Record) : {}; } catch { return {}; diff --git a/apps/cli/src/lib/opencode-oauth.ts b/apps/cli/src/lib/opencode-oauth.ts index ee28afe4..6f975a36 100644 --- a/apps/cli/src/lib/opencode-oauth.ts +++ b/apps/cli/src/lib/opencode-oauth.ts @@ -243,7 +243,9 @@ const readAuthFile = async (): Promise> => { const file = Bun.file(filepath); if (!(await file.exists())) return {}; try { - const content = await file.json(); + const text = await file.text(); + if (text.trim().length === 0) return {}; + const content = JSON.parse(text) as unknown; return content && typeof content === 'object' ? (content as Record) : {}; } catch { return {}; diff --git a/apps/docs/btca.spec.md b/apps/docs/btca.spec.md index 6595f40d..fd74d28d 100644 --- a/apps/docs/btca.spec.md +++ b/apps/docs/btca.spec.md @@ -48,7 +48,7 @@ Supported providers: - `openai` — OAuth (no API keys) - `openai-compat` — optional API key (requires baseURL + name in config) - `anthropic` — API key -- `google` — API key or OAuth +- `google` — API key - `minimax` — API key Environment variable overrides: @@ -202,7 +202,7 @@ Options: - `-g, --global` — (flag exists; config target is still resolved by presence of project config) - `-n, --name ` -- `-b, --branch ` (default `main`) +- `-b, --branch ` (auto-detected when omitted) - `-s, --search-path ` - `--notes ` - `-t, --type ` @@ -275,6 +275,7 @@ Behavior: - If provider/model specified, updates config. - Otherwise, interactive provider selection (connected providers listed first), then model selection. - Prompts for auth if required. +- Backward-compatible alias: `btca config model --provider --model ` (deprecated). ### 4.8 `btca disconnect` diff --git a/apps/docs/guides/authentication.mdx b/apps/docs/guides/authentication.mdx index ab779c09..36e7e8bb 100644 --- a/apps/docs/guides/authentication.mdx +++ b/apps/docs/guides/authentication.mdx @@ -18,7 +18,7 @@ Supported providers: - `github-copilot` (OAuth device flow) - `openai-compat` (optional API key) - `anthropic` (API key) -- `google` (API key or OAuth) +- `google` (API key) - `minimax` (API key) Environment variable overrides: diff --git a/apps/server/README.md b/apps/server/README.md index e8848e67..652d0ecb 100644 --- a/apps/server/README.md +++ b/apps/server/README.md @@ -159,7 +159,7 @@ BTCA supports the following providers only: - `opencode` — API key required - `openrouter` — API key required - `openai` — OAuth only -- `google` — API key or OAuth +- `google` — API key required - `anthropic` — API key required Authenticate providers via OpenCode: @@ -173,7 +173,7 @@ opencode auth --provider - OpenCode and OpenRouter can use environment variables or OpenCode auth. - OpenAI requires OAuth (API keys are not supported). - Anthropic requires an API key. -- Google supports API key or OAuth. +- Google requires an API key. ## Environment Variables diff --git a/apps/server/src/providers/auth.ts b/apps/server/src/providers/auth.ts index 277de9a7..8db96bca 100644 --- a/apps/server/src/providers/auth.ts +++ b/apps/server/src/providers/auth.ts @@ -27,7 +27,7 @@ export namespace Auth { openai: ['oauth'], 'openai-compat': ['api'], anthropic: ['api'], - google: ['api', 'oauth'], + google: ['api'], minimax: ['api'] }; @@ -103,7 +103,11 @@ export namespace Auth { return {}; } - const result = await Result.tryPromise(() => file.json()); + const result = await Result.tryPromise(async () => { + const text = await file.text(); + if (text.trim().length === 0) return {}; + return JSON.parse(text) as unknown; + }); return result.match({ ok: (content) => { const parsed = AuthFileSchema.safeParse(content); @@ -172,7 +176,7 @@ export namespace Auth { case 'anthropic': return 'Run "opencode auth --provider anthropic" and enter an API key.'; case 'google': - return 'Run "opencode auth --provider google" and enter an API key or OAuth.'; + return 'Run "btca connect -p google" and enter an API key.'; case 'openrouter': return 'Set OPENROUTER_API_KEY or run "opencode auth --provider openrouter".'; case 'opencode':