Files
opencode-manager/frontend/src/api/oauth.ts
T
Chris Scott 5de419ee28 fix issues (#136)
* fix: prevent delete button click when card is not swiped open

* refactor: improve CreateRepoInput type safety

* security: require AUTH_SECRET and use secure random generation

* fix: SSH key path validation, async passphrase stripping, and port handling

* fix: use correct console methods for logger levels

* Add error handling to DB update functions and improve migration logging

* Add error handling for session lookup in auth middleware

* Add structured git error handling with user-friendly messages

- Parse git errors with specific error codes (AUTH_FAILED, REPO_NOT_FOUND,
  PUSH_REJECTED, MERGE_CONFLICT, etc.) and appropriate HTTP status codes
- Return structured error responses with summary and detail from backend
- Add GitErrorBanner component for better error display in UI
- Add optional onError callback to useGit hook for external error handling

* Make IPC server initialization/disposal async and fix SSH host key handler

* add try-catch error handling in frontend lib utilities

* remove unresolved promise handlers in speech synthesizer callbacks

* Extract error types to shared package

* Import GitErrorCode from shared package

* Refactor API layer to use shared FetchError and fetchWrapper

* Update prompt parser and source control components

* Extract MCP server list to separate component with improved badge menu UX

* merge useSettingsDialogUrl into useSettingsDialog and extract getRepoDisplayName utility

* add separate loading state for passkey sign in

* refactor hooks: use fetchWrapper, improve error handling, add proper types

* replace browser confirm() with DeleteDialog component in settings

* fix: add missing variables parameter in React Query onError callbacks

* Refactor message parts to use separate Zustand store

* Update QuestionPrompt styling for light/dark mode
2026-02-15 19:48:03 -05:00

67 lines
1.8 KiB
TypeScript

import { API_BASE_URL } from "@/config"
import { fetchWrapper, FetchError } from "./fetchWrapper"
export interface OAuthAuthorizeResponse {
url: string
method: "code"
instructions: string
}
export interface OAuthCallbackRequest {
method: number
code?: string
}
export interface ProviderAuthMethod {
type: "oauth" | "api"
label: string
}
export interface ProviderAuthMethods {
[providerId: string]: ProviderAuthMethod[]
}
function handleApiError(error: unknown, context: string): never {
if (error instanceof FetchError) {
throw new Error(`${context}: ${error.message}`)
}
throw error
}
export const oauthApi = {
authorize: async (providerId: string, method: number): Promise<OAuthAuthorizeResponse> => {
try {
return await fetchWrapper(`${API_BASE_URL}/api/oauth/${providerId}/oauth/authorize`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ method }),
})
} catch (error) {
handleApiError(error, "OAuth authorization failed")
}
},
callback: async (providerId: string, request: OAuthCallbackRequest): Promise<boolean> => {
try {
return await fetchWrapper(`${API_BASE_URL}/api/oauth/${providerId}/oauth/callback`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(request),
})
} catch (error) {
handleApiError(error, "OAuth callback failed")
}
},
getAuthMethods: async (): Promise<ProviderAuthMethods> => {
try {
const { providers, ...rest } = await fetchWrapper<{ providers?: ProviderAuthMethods } & ProviderAuthMethods>(
`${API_BASE_URL}/api/oauth/auth-methods`
)
return providers || rest
} catch (error) {
handleApiError(error, "Failed to get provider auth methods")
}
},
}