mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
The desktop app now has a dedicated OpenAI OAuth API client and store mirroring the existing Claude Official flow. The component uses the existing browser-open plus polling pattern and never exposes token material to the UI. Constraint: OAuth status responses must not return token bodies Rejected: Reuse Claude OAuth store | the status shape and endpoint differ Confidence: high Scope-risk: narrow Tested: cd desktop && bun run test -- src/stores/hahaOpenAIOAuthStore.test.ts Tested: git diff --check
39 lines
916 B
TypeScript
39 lines
916 B
TypeScript
// desktop/src/api/hahaOpenAIOAuth.ts
|
|
|
|
import { api, getBaseUrl } from './client'
|
|
|
|
export type HahaOpenAIOAuthStatus =
|
|
| { loggedIn: false }
|
|
| {
|
|
loggedIn: true
|
|
expiresAt: number | null
|
|
email: string | null
|
|
accountId: string | null
|
|
}
|
|
|
|
function currentServerPort(): number {
|
|
const port = new URL(getBaseUrl()).port
|
|
const parsed = Number.parseInt(port, 10)
|
|
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
throw new Error(`Cannot determine server port from baseUrl: ${getBaseUrl()}`)
|
|
}
|
|
return parsed
|
|
}
|
|
|
|
export const hahaOpenAIOAuthApi = {
|
|
start() {
|
|
return api.post<{ authorizeUrl: string; state: string }>(
|
|
'/api/haha-openai-oauth/start',
|
|
{ serverPort: currentServerPort() },
|
|
)
|
|
},
|
|
|
|
status() {
|
|
return api.get<HahaOpenAIOAuthStatus>('/api/haha-openai-oauth')
|
|
},
|
|
|
|
logout() {
|
|
return api.delete<{ ok: true }>('/api/haha-openai-oauth')
|
|
},
|
|
}
|