Skip to content

Commit 37e7db7

Browse files
committed
feat(auth): add support for interactive OpenCode provider additions when authenticated
- Implemented `handleOpenCodeAddProvider` for managing multiple OpenCode providers interactively. - Added special handling for authenticated OpenCode scenarios in `use-home-commands`. - Removed unused `createCredentialFile` import from OpenCode auth module.
1 parent e3b8add commit 37e7db7

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
@@ -154,6 +154,12 @@ export function useHomeCommands(options: UseHomeCommandsOptions) {
154154

155155
const isAuthenticated = await engine.auth.isAuthenticated()
156156

157+
// Special handling for OpenCode when already authenticated
158+
if (providerId === "opencode" && isAuthenticated) {
159+
await handleOpenCodeAddProvider(providerId, providerName)
160+
return
161+
}
162+
157163
if (isAuthenticated) {
158164
toast.show({
159165
variant: "info",
@@ -175,6 +181,40 @@ export function useHomeCommands(options: UseHomeCommandsOptions) {
175181
))
176182
}
177183

184+
/**
185+
* Handles adding another OpenCode provider by spawning `opencode auth login` interactively
186+
*/
187+
const handleOpenCodeAddProvider = async (providerId: string, providerName: string) => {
188+
const { registry } = await import("../../../../../infra/engines/index.js")
189+
190+
dialog.show(() => (
191+
<SelectMenu
192+
message={`${providerName} is authenticated. Add another provider?`}
193+
choices={[
194+
{ title: "Add another provider", value: "add" },
195+
{ title: "Cancel", value: "cancel" },
196+
]}
197+
onSelect={async (choice: string) => {
198+
dialog.close()
199+
if (choice === "cancel") return
200+
201+
const engine = registry.get(providerId)
202+
if (!engine) return
203+
204+
await dialog.handleAuthCommand(
205+
`${providerName} - Add Provider`,
206+
async () => {
207+
// Call ensureAuth(true) directly to force interactive login
208+
// This bypasses handleLogin's clack confirmation which doesn't work well after TUI destruction
209+
await engine.auth.ensureAuth(true)
210+
}
211+
)
212+
}}
213+
onCancel={() => dialog.close()}
214+
/>
215+
))
216+
}
217+
178218
const handleLogoutCommand = async () => {
179219
const { registry } = await import("../../../../../infra/engines/index.js")
180220
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)