Skip to content

fix: render custom oauth provider icon on login button and provider table - #6581

Open
feitianbubu wants to merge 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/028b5e199
Open

fix: render custom oauth provider icon on login button and provider table#6581
feitianbubu wants to merge 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/028b5e199

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

自定义 OAuth 提供商后台设置的icon 字段(预设模板也会自动填 github/gitlab 等),没有生效:登录页按钮不渲染图标,管理端列表只把它当纯文本显示。
image

改动:

  • 登录页自定义提供商按钮:icon 非空时经 getLobeIcon() 渲染,和内置提供商按钮外观一致
  • 管理端提供商列表图标列:从显示原始字符串改为渲染真实图标
  • getLobeIcon 增加大小写不敏感解析:配置里常存小写(如 github),而 @lobehub/icons 导出是 PascalCase(Github)。映射只收组件导出(过滤 tocuseFillId*Mappings 等非组件导出,避免坏配置字符串导致登录页渲染崩溃),用 null-prototype 字典防 constructor 这类原型键穿透。lobehub 没有的名字维持原有首字母占位兜底

🚀 变更类型 / 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

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The changes add case-insensitive icon lookup and use getLobeIcon to render configured custom OAuth provider icons in sign-in buttons and the provider table.

Changes

OAuth icon rendering

Layer / File(s) Summary
Case-insensitive icon resolution
web/src/lib/lobe-icon.tsx
The icon resolver indexes valid custom and LobeHub icon exports by lowercase name before fallback resolution.
Provider icon rendering
web/src/features/auth/components/oauth-providers.tsx, web/src/features/system-settings/auth/custom-oauth/components/provider-table.tsx
OAuth buttons render configured icons at size 16. The provider table renders icons at size 20 through getLobeIcon.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: calcium-ion

Poem

A rabbit hops through icons bright,
Case-folded names now land just right.
Buttons glow at sixteen small,
Tables show them twenty tall.
Shared paths guide each provider’s call.

🚥 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 describes the main change: rendering custom OAuth provider icons on the login button and provider table.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/src/features/auth/components/oauth-providers.tsx`:
- Line 147: Update the icon assignment in the OAuth provider configuration to
wrap the getLobeIcon(provider.icon, 16) output in an element marked
aria-hidden="true", while preserving the undefined behavior when no icon is
configured and ensuring fallback text cannot affect the button’s accessible
name.

In `@web/src/lib/lobe-icon.tsx`:
- Around line 122-124: Guard the dynamic lookups in the icon resolution flow
around baseKey, CustomIcon, and BaseIcon so inherited properties such as
constructor, toString, and hasOwnProperty are rejected. Use
Object.prototype.hasOwnProperty.call or equivalent own-key validation for
CUSTOM_ICONS and LobeIcons before rendering, and make invalid keys fall back
through the existing fallback behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d3c6cfc6-f0a3-471f-a9a1-a88d99c6d9d5

📥 Commits

Reviewing files that changed from the base of the PR and between cfaba1d and 16bbfd6.

📒 Files selected for processing (3)
  • web/src/features/auth/components/oauth-providers.tsx
  • web/src/features/system-settings/auth/custom-oauth/components/provider-table.tsx
  • web/src/lib/lobe-icon.tsx

key: `custom-${provider.slug}`,
label: t('Continue with {{name}}', { name: provider.name }),
onClick: () => handleCustomOAuthLogin(provider),
icon: provider.icon ? getLobeIcon(provider.icon, 16) : undefined,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Mark the configured icon as decorative.

The button already exposes the provider name through label. The new icon is decorative, but getLobeIcon is not marked with aria-hidden. Its fallback contains visible text, so an invalid icon can alter the accessible name.

Wrap the icon output in an aria-hidden="true" element, or add equivalent handling in getLobeIcon.

As per coding guidelines, decorative icons must use aria-hidden="true".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/features/auth/components/oauth-providers.tsx` at line 147, Update the
icon assignment in the OAuth provider configuration to wrap the
getLobeIcon(provider.icon, 16) output in an element marked aria-hidden="true",
while preserving the undefined behavior when no icon is configured and ensuring
fallback text cannot affect the button’s accessible name.

Source: Coding guidelines

Comment thread web/src/lib/lobe-icon.tsx
Comment on lines +122 to 124
const baseKey =
ICON_KEYS_BY_LOWERCASE[segments[0].toLowerCase()] ?? segments[0]
const CustomIcon = CUSTOM_ICONS[baseKey]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

rg -n 'getLobeIcon|constructor|__proto__|hasOwnProperty' web/src --glob '*.{ts,tsx}'

Repository: QuantumNous/new-api

Length of output: 4326


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '--- file outline ---\n'
ast-grep outline web/src/lib/lobe-icon.tsx || true

printf '\n--- relevant source ---\n'
sed -n '1,180p' web/src/lib/lobe-icon.tsx

printf '\n--- direct object lookup probe for key types ---\n'
node - <<'JS'
const CUSTOM_ICONS = {}
const LobeIcons = {}

for (const key of ['constructor', '__proto__', 'toString', 'valueOf', 'hasOwnProperty', 'OpenAI']) {
  const base = key
  console.log(`${key}: custom=${!!CUSTOM_ICONS[base]}, baseKeys=${!!LobeIcons[base]}`)
}
JS

Repository: QuantumNous/new-api

Length of output: 248


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf -- '%s\n' '--- file outline ---'
ast-grep outline web/src/lib/lobe-icon.tsx || true

printf -- '%s\n' ''
printf -- '%s\n' '--- relevant source ---'
sed -n '1,180p' web/src/lib/lobe-icon.tsx

printf -- '%s\n' ''
printf -- '%s\n' '--- direct object lookup probe for key types ---'
node - <<'JS'
const CUSTOM_ICONS = {}
const LobeIcons = {}

for (const key of ['constructor', '__proto__', 'toString', 'valueOf', 'hasOwnProperty', 'OpenAI']) {
  const base = key
  console.log(`${key}: custom=${!!CUSTOM_ICONS[base]}, lobeIcons=${!!LobeIcons[base]}`)
}
JS

Repository: QuantumNous/new-api

Length of output: 6189


Guard dynamic registry lookups before rendering.

ICON_KEYS_BY_LOWERCASE only blocks prototype keys before the fallback to segments[0]. CUSTOM_ICONS[baseKey] and LobeIcons[baseKey] still resolve inherited properties such as constructor, toString, and hasOwnProperty, so those keys can reach CustomIcon rendering or BaseIcon[segments[1]] evaluation. Use Object.prototype.hasOwnProperty.call or null-prototype registries before accepting a resolved icon; invalid icon keys should always fall back.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/lib/lobe-icon.tsx` around lines 122 - 124, Guard the dynamic lookups
in the icon resolution flow around baseKey, CustomIcon, and BaseIcon so
inherited properties such as constructor, toString, and hasOwnProperty are
rejected. Use Object.prototype.hasOwnProperty.call or equivalent own-key
validation for CUSTOM_ICONS and LobeIcons before rendering, and make invalid
keys fall back through the existing fallback behavior.

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.

Custom OAuth provider icons are not rendered in the new UI

2 participants