Skip to content

fix: custom oauth binding status never shown due to id type mismatch - #6573

Open
feitianbubu wants to merge 1 commit into
QuantumNous:mainfrom
feitianbubu:fix-custom-oauth-binding-display
Open

feitianbubu wants to merge 1 commit into
QuantumNous:mainfrom
feitianbubu:fix-custom-oauth-binding-display

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Jul 31, 2026

Copy link
Copy Markdown
Member

⚠️ 提交说明 / PR Notice

个人资料页「账户绑定」里,自定义 OAuth 提供商永远显示「未绑定」,即使 user_oauth_bindings 表里有绑定记录。

原因:后端 /api/user/oauth/bindings 返回的 provider_id 是 JSON 数字(Go int),前端却用 b.provider_id === String(provider.id) 严格比较,数字和字符串永远不相等,所以 isBound 恒为 false。另外前端接口声明的 external_id 字段后端并不返回(实际字段叫 provider_user_id),绑定卡片上也一直显示不出第三方身份 ID。

改法:前端类型声明对齐后端响应(provider_id: numberprovider_user_id),按数字直接比较,卡片显示改用 provider_user_id

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix)
  • ✨ 新功能 (New feature)
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • 无(自测发现,前端显示层类型比较错误,非设计取舍)

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

修复前:
image

修复后:
image

Summary by CodeRabbit

  • Bug Fixes
    • Improved custom OAuth account binding compatibility by using numeric provider identifiers.
    • Updated bound account details to display the correct provider user identifier.
    • Improved unbinding behavior for custom OAuth providers.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Custom OAuth binding types now use numeric provider IDs and provider_user_id. Account binding lookup, display, and unbind calls use the updated identifiers.

Changes

Custom OAuth binding updates

Layer / File(s) Summary
Align custom OAuth binding contract and account display
web/src/features/profile/api.ts, web/src/features/profile/components/tabs/account-bindings-tab.tsx
CustomOAuthBinding uses numeric provider_id and optional provider_user_id. unbindCustomOAuth accepts a numeric provider ID. Account binding lookup compares provider IDs directly and displays provider_user_id.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: calcium-ion

Poem

A rabbit hops through OAuth bright,
With numbered keys aligned just right.
User IDs now show their name,
Bind and unbind share the same game.
Nibble, click, and ship tonight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the custom OAuth binding display bug caused by an ID type mismatch.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Blz-Galaxy

Copy link
Copy Markdown

本地在 new-api-main 当前代码中复核,确认这个 PR 描述的问题仍可由现有前后端字段不一致解释:

  1. 后端 /api/user/oauth/bindings 的响应结构里,provider_id 是 Go int,序列化后为 JSON number;外部身份字段返回为 provider_user_id

    • controller/custom_oauth.go: UserOAuthBindingResponse.ProviderId int
    • controller/custom_oauth.go: ProviderUserId string \json:"provider_user_id"``
  2. 前端个人资料页的自定义 OAuth 绑定判断使用了严格比较:

    • web/src/features/profile/components/tabs/account-bindings-tab.tsx
    • customBindings.find((b) => b.provider_id === String(provider.id))

    运行时实际会变成 number === string,因此即使 user_oauth_bindings 已有记录,也匹配不到,isBound 会保持 false

  3. 前端类型也声明为 external_id?: string,但后端实际返回 provider_user_id,所以即使绑定项匹配到了,卡片里的外部身份 ID 也不会按当前字段名正常显示。

结论:这个修复方向是对的,至少需要让前端对齐后端响应字段,或在比较时统一 provider_id 类型,并将显示字段从 external_id 改为兼容/使用 provider_user_id

@Blz-Galaxy

Blz-Galaxy commented Aug 2, 2026

Copy link
Copy Markdown

麻烦快点审核修复吧~
就是这个 自定义 OAuth 提供商永远显示「未绑定」 导致了 #2990 #5215 #5216

@feitianbubu

Copy link
Copy Markdown
Member Author

@ 作者 可以加速 :P

@Blz-Galaxy

Copy link
Copy Markdown

@ 作者 可以加速 :P

@Calcium-Ion @seefs001 @songquanpeng :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants