fix(openai): buildCredentials 对齐后端 BuildAccountCredentials 字段
补齐前端 buildCredentials 缺失的 id_token、email、plan_type 字段, 与后端 BuildAccountCredentials 保持一致。修复手动 RT 创建的账号 缺少订阅类型等关键信息的问题。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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<string, unknown> => {
|
||||
const creds: Record<string, unknown> = {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user