Skip to content

Commit 2456c56

Browse files
authored
Merge pull request #75 from moazbuilds/fix/opencode_auth
feat(auth): add support for interactive OpenCode provider additions when authenticated
2 parents 6d3b26a + 37e7db7 commit 2456c56

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

src/cli/tui/routes/home/hooks/use-home-commands.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ export function useHomeCommands(options: UseHomeCommandsOptions) {
200200

201201
const isAuthenticated = await engine.auth.isAuthenticated()
202202

203+
// Special handling for OpenCode when already authenticated
204+
if (providerId === "opencode" && isAuthenticated) {
205+
await handleOpenCodeAddProvider(providerId, providerName)
206+
return
207+
}
208+
203209
if (isAuthenticated) {
204210
toast.show({
205211
variant: "info",
@@ -221,6 +227,40 @@ export function useHomeCommands(options: UseHomeCommandsOptions) {
221227
))
222228
}
223229

230+
/**
231+
* Handles adding another OpenCode provider by spawning `opencode auth login` interactively
232+
*/
233+
const handleOpenCodeAddProvider = async (providerId: string, providerName: string) => {
234+
const { registry } = await import("../../../../../infra/engines/index.js")
235+
236+
dialog.show(() => (
237+
<SelectMenu
238+
message={`${providerName} is authenticated. Add another provider?`}
239+
choices={[
240+
{ title: "Add another provider", value: "add" },
241+
{ title: "Cancel", value: "cancel" },
242+
]}
243+
onSelect={async (choice: string) => {
244+
dialog.close()
245+
if (choice === "cancel") return
246+
247+
const engine = registry.get(providerId)
248+
if (!engine) return
249+
250+
await dialog.handleAuthCommand(
251+
`${providerName} - Add Provider`,
252+
async () => {
253+
// Call ensureAuth(true) directly to force interactive login
254+
// This bypasses handleLogin's clack confirmation which doesn't work well after TUI destruction
255+
await engine.auth.ensureAuth(true)
256+
}
257+
)
258+
}}
259+
onCancel={() => dialog.close()}
260+
/>
261+
))
262+
}
263+
224264
const handleLogoutCommand = async () => {
225265
const { registry } = await import("../../../../../infra/engines/index.js")
226266
const { handleLogout } = await import("../../../../commands/auth.command.js")

src/infra/engines/providers/opencode/auth.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
displayCliNotInstalledError,
88
isCommandNotFoundError,
99
ensureAuthDirectory,
10-
createCredentialFile,
1110
} from '../../core/auth.js';
1211
import { metadata } from './metadata.js';
1312
import { ENV } from './config.js';

0 commit comments

Comments
 (0)