Skip to content

Commit 1f05d9f

Browse files
QTomclaude
andcommitted
fix(openai): buildCredentials 对齐后端 BuildAccountCredentials 字段
补齐前端 buildCredentials 缺失的 id_token、email、plan_type 字段, 与后端 BuildAccountCredentials 保持一致。修复手动 RT 创建的账号 缺少订阅类型等关键信息的问题。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9f8cffe commit 1f05d9f

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

frontend/src/composables/useOpenAIOAuth.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface OpenAITokenInfo {
1313
scope?: string
1414
email?: string
1515
name?: string
16+
plan_type?: string
1617
// OpenAI specific IDs (extracted from ID Token)
1718
chatgpt_account_id?: string
1819
chatgpt_user_id?: string
@@ -185,22 +186,23 @@ export function useOpenAIOAuth(options?: UseOpenAIOAuthOptions) {
185186
}
186187
}
187188

188-
// Build credentials for OpenAI OAuth account
189+
// Build credentials for OpenAI OAuth account (aligned with backend BuildAccountCredentials)
189190
const buildCredentials = (tokenInfo: OpenAITokenInfo): Record<string, unknown> => {
190191
const creds: Record<string, unknown> = {
191192
access_token: tokenInfo.access_token,
192-
refresh_token: tokenInfo.refresh_token,
193-
token_type: tokenInfo.token_type,
194-
expires_in: tokenInfo.expires_in,
195-
expires_at: tokenInfo.expires_at,
196-
scope: tokenInfo.scope
193+
expires_at: tokenInfo.expires_at
197194
}
198195

199-
if (tokenInfo.client_id) {
200-
creds.client_id = tokenInfo.client_id
196+
// 仅在返回了新的 refresh_token 时才写入,防止用空值覆盖已有令牌
197+
if (tokenInfo.refresh_token) {
198+
creds.refresh_token = tokenInfo.refresh_token
199+
}
200+
if (tokenInfo.id_token) {
201+
creds.id_token = tokenInfo.id_token
202+
}
203+
if (tokenInfo.email) {
204+
creds.email = tokenInfo.email
201205
}
202-
203-
// Include OpenAI specific IDs (required for forwarding)
204206
if (tokenInfo.chatgpt_account_id) {
205207
creds.chatgpt_account_id = tokenInfo.chatgpt_account_id
206208
}
@@ -210,6 +212,12 @@ export function useOpenAIOAuth(options?: UseOpenAIOAuthOptions) {
210212
if (tokenInfo.organization_id) {
211213
creds.organization_id = tokenInfo.organization_id
212214
}
215+
if (tokenInfo.plan_type) {
216+
creds.plan_type = tokenInfo.plan_type
217+
}
218+
if (tokenInfo.client_id) {
219+
creds.client_id = tokenInfo.client_id
220+
}
213221

214222
return creds
215223
}

0 commit comments

Comments
 (0)