diff --git a/frontend/src/composables/useOpenAIOAuth.ts b/frontend/src/composables/useOpenAIOAuth.ts index 8f8d7075..b3a8ed87 100644 --- a/frontend/src/composables/useOpenAIOAuth.ts +++ b/frontend/src/composables/useOpenAIOAuth.ts @@ -13,6 +13,7 @@ export interface OpenAITokenInfo { scope?: string email?: string name?: string + plan_type?: string // OpenAI specific IDs (extracted from ID Token) chatgpt_account_id?: string chatgpt_user_id?: string @@ -185,22 +186,23 @@ export function useOpenAIOAuth(options?: UseOpenAIOAuthOptions) { } } - // Build credentials for OpenAI OAuth account + // Build credentials for OpenAI OAuth account (aligned with backend BuildAccountCredentials) const buildCredentials = (tokenInfo: OpenAITokenInfo): Record => { const creds: Record = { access_token: tokenInfo.access_token, - refresh_token: tokenInfo.refresh_token, - token_type: tokenInfo.token_type, - expires_in: tokenInfo.expires_in, - expires_at: tokenInfo.expires_at, - scope: tokenInfo.scope + expires_at: tokenInfo.expires_at } - if (tokenInfo.client_id) { - creds.client_id = tokenInfo.client_id + // 仅在返回了新的 refresh_token 时才写入,防止用空值覆盖已有令牌 + if (tokenInfo.refresh_token) { + creds.refresh_token = tokenInfo.refresh_token + } + if (tokenInfo.id_token) { + creds.id_token = tokenInfo.id_token + } + if (tokenInfo.email) { + creds.email = tokenInfo.email } - - // Include OpenAI specific IDs (required for forwarding) if (tokenInfo.chatgpt_account_id) { creds.chatgpt_account_id = tokenInfo.chatgpt_account_id } @@ -210,6 +212,12 @@ export function useOpenAIOAuth(options?: UseOpenAIOAuthOptions) { if (tokenInfo.organization_id) { creds.organization_id = tokenInfo.organization_id } + if (tokenInfo.plan_type) { + creds.plan_type = tokenInfo.plan_type + } + if (tokenInfo.client_id) { + creds.client_id = tokenInfo.client_id + } return creds }