Skip to content

fix: optimized the GitHub login copy and timeout. - #2244

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/github-oauth
Nov 19, 2025
Merged

fix: optimized the GitHub login copy and timeout.#2244
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/github-oauth

Conversation

@seefs001

@seefs001 seefs001 commented Nov 19, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Fixed repeated GitHub authentication attempts by preventing button clicks during login flow.
  • Improvements

    • Extended GitHub authentication timeout window from 5 to 20 seconds for improved reliability.
    • Added visual feedback indicating GitHub redirect is in progress.
    • Implemented timeout notifications across all supported languages with guidance to refresh and retry.

@coderabbitai

coderabbitai Bot commented Nov 19, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This PR extends GitHub OAuth timeout handling by increasing the backend HTTP client timeout from 5 to 20 seconds for token exchange requests, and adding corresponding frontend UI feedback mechanisms with a 20-second timeout handler that updates button text and disabled state, accompanied by internationalized timeout messages.

Changes

Cohort / File(s) Summary
Backend timeout configuration
controller/github.go
Increased HTTP client timeout in getGitHubUserInfoByCode from 5 seconds to 20 seconds to allow more time for GitHub token exchange requests.
Frontend GitHub OAuth UI state
web/src/components/auth/LoginForm.jsx, web/src/components/auth/RegisterForm.jsx
Added GitHub-specific button state management with dynamic text labels, disabled state to prevent repeated clicks, and a 20-second timeout mechanism using useRef. Button displays "Redirecting to GitHub..." during login and reverts to "Request timed out..." if timeout occurs. Includes proper cleanup via useEffect.
Internationalization
web/src/i18n/locales/en.json, web/src/i18n/locales/fr.json, web/src/i18n/locales/ja.json, web/src/i18n/locales/ru.json, web/src/i18n/locales/zh.json
Added two new translation keys across all locale files: "正在跳转 GitHub..." (Redirecting to GitHub) and "请求超时,请刷新页面后重新发起 GitHub 登录" (Request timed out, please refresh and restart GitHub login).

Sequence Diagram

sequenceDiagram
    participant User
    participant LoginForm as LoginForm/RegisterForm
    participant Backend as Backend
    participant GitHub as GitHub OAuth
    
    User->>LoginForm: Click GitHub Login
    activate LoginForm
    LoginForm->>LoginForm: Set button text to "Redirecting..."
    LoginForm->>LoginForm: Disable button
    LoginForm->>LoginForm: Start 20s timeout ref
    LoginForm->>Backend: Initiate OAuth flow
    deactivate LoginForm
    
    Backend->>GitHub: Request token exchange (20s timeout)
    
    alt Success within 20s
        GitHub-->>Backend: Return token
        Backend-->>LoginForm: OAuth success
        LoginForm->>LoginForm: Clear timeout, proceed
    else Timeout after 20s
        LoginForm->>LoginForm: Timeout fired
        LoginForm->>LoginForm: Update button to "Request timed out..."
        LoginForm->>LoginForm: Re-disable button
        Note over LoginForm: User must refresh
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Areas requiring attention:
    • Verify timeout value (20s) is consistent between backend (controller/github.go) and frontend (LoginForm.jsx, RegisterForm.jsx)
    • Confirm cleanup logic in useEffect properly clears the timeout ref to prevent memory leaks
    • Validate that both LoginForm and RegisterForm implementations follow identical patterns for consistency
    • Review translation keys are correctly used in the UI state updates across both components

Poem

🐰 With GitHub timeouts extended true,
The button talks—"redirecting" for you!
Twenty seconds to dance with the cloud,
If it stalls, we tell it aloud.
In five tongues we speak: fast and proud! 🌍

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: it addresses GitHub login optimization with improved UI copy (translations) and timeout handling (20-second timeout implementation).
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
web/src/components/auth/RegisterForm.jsx (1)

246-265: Consider timeout value and retry UX

Two observations about the timeout implementation:

  1. Timeout race condition: The 20-second frontend timeout matches the backend timeout exactly. Frontend should wait slightly longer (e.g., 22-25 seconds) to account for network latency and avoid showing timeout before the backend actually times out.

  2. No retry mechanism: After timeout, the button remains permanently disabled with an error message. Users must refresh the page to try again. Consider allowing retry:

 githubTimeoutRef.current = setTimeout(() => {
   setGithubLoading(false);
   setGithubButtonText(t('请求超时,请刷新页面后重新发起 GitHub 登录'));
-  setGithubButtonDisabled(true);
+  setGithubButtonDisabled(false);  // Allow retry
-}, 20000);
+}, 22000);  // Wait slightly longer than backend
  1. Redundant timeout: The setTimeout on line 263 that clears loading after 3 seconds is now redundant since the main timeout handles this at 20 seconds.
web/src/components/auth/LoginForm.jsx (1)

274-299: Same timeout concerns as RegisterForm

This implementation has the same issues identified in RegisterForm.jsx:

  1. The 20-second timeout should be slightly longer (22-25 seconds) to avoid racing with the backend
  2. The button remains permanently disabled after timeout with no retry option
  3. The setTimeout on line 297 is redundant

Consider applying the same fixes suggested for RegisterForm to maintain consistency.

🧹 Nitpick comments (3)
web/src/i18n/locales/ru.json (1)

2102-2103: Streamline RU timeout phrasing for clarity.

Suggested wording:

-    "请求超时,请刷新页面后重新发起 GitHub 登录": "Время ожидания истекло, обновите страницу и снова запустите вход через GitHub"
+    "请求超时,请刷新页面后重新发起 GitHub 登录": "Время ожидания истекло. Обновите страницу и повторите вход через GitHub."

Reuse the locale/UI verification script from the EN comment to confirm presence and usage across the codebase.

web/src/components/auth/RegisterForm.jsx (1)

88-90: Use i18n for initial button text

The githubButtonText state is initialized with a hardcoded Chinese string. For consistency with i18n best practices, consider initializing with t('使用 GitHub 继续') or storing just the key and always calling t() when rendering.

-const [githubButtonText, setGithubButtonText] = useState('使用 GitHub 继续');
+const [githubButtonText, setGithubButtonText] = useState(t('使用 GitHub 继续'));

Alternatively, you could store the translation key and always call t() when rendering to avoid stale translations if the language changes.

web/src/components/auth/LoginForm.jsx (1)

90-92: Use i18n for initial button text (consistent with RegisterForm)

Same issue as in RegisterForm: the githubButtonText state is initialized with a hardcoded Chinese string. Consider initializing with t('使用 GitHub 继续') for proper i18n support.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 62edac7 and 1fc3c4b.

📒 Files selected for processing (8)
  • controller/github.go (1 hunks)
  • web/src/components/auth/LoginForm.jsx (5 hunks)
  • web/src/components/auth/RegisterForm.jsx (5 hunks)
  • web/src/i18n/locales/en.json (1 hunks)
  • web/src/i18n/locales/fr.json (1 hunks)
  • web/src/i18n/locales/ja.json (1 hunks)
  • web/src/i18n/locales/ru.json (1 hunks)
  • web/src/i18n/locales/zh.json (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
web/src/components/auth/RegisterForm.jsx (1)
web/src/components/auth/LoginForm.jsx (3)
  • githubButtonText (90-90)
  • githubButtonDisabled (91-91)
  • githubTimeoutRef (92-92)
web/src/components/auth/LoginForm.jsx (1)
web/src/components/auth/RegisterForm.jsx (3)
  • githubButtonText (88-88)
  • githubButtonDisabled (89-89)
  • githubTimeoutRef (90-90)
🔇 Additional comments (7)
web/src/i18n/locales/zh.json (1)

2074-2076: LGTM! GitHub OAuth translations added correctly.

The Chinese translations for GitHub login flow have been properly added:

  • "正在跳转 GitHub..." (Redirecting to GitHub...)
  • Timeout error message with user guidance

The JSON formatting is correct, with the previous entry updated to include a trailing comma.

web/src/i18n/locales/fr.json (1)

2092-2094: LGTM! French translations added correctly.

The French translations for the GitHub OAuth flow have been properly added:

  • "Redirection vers GitHub..." (Redirecting to GitHub...)
  • "Délai dépassé, veuillez actualiser la page puis relancer la connexion GitHub" (Timeout, please refresh the page and restart GitHub login)

The JSON formatting is correct, and the translations appear grammatically sound.

If you have French-speaking users, consider having a native speaker verify the timeout message phrasing sounds natural. The current translation is grammatically correct but could potentially be refined for better user experience.

controller/github.go (1)

47-47: The response times show both GitHub endpoints respond very quickly (0.13s and 0.12s), which means a 20-second timeout is quite generous. Let me verify what GitHub's API documentation recommends for timeout handling.

No action required—the 20-second timeout is appropriate.

Measured response times show GitHub's OAuth and user endpoints respond in ~0.1-0.13 seconds, well under the 20-second timeout. While this may seem conservative, timeouts accommodate network latency, connection establishment, and transient server conditions—not just endpoint response time. Real-world experience shows longer timeouts become necessary for slower internet connections, and 20 seconds aligns with common practice for OAuth integrations handling multiple sequential API calls. The 5-second original timeout may have been insufficient under adverse network conditions.

web/src/i18n/locales/ja.json (1)

2083-2085: LGTM: GitHub OAuth timeout translations added

The new Japanese translations correctly support the GitHub OAuth timeout flow implemented in the login/register forms. The trailing comma addition on line 2083 follows JSON formatting best practices.

web/src/components/auth/RegisterForm.jsx (2)

134-140: LGTM: Proper timeout cleanup

The cleanup effect correctly clears the timeout on component unmount, preventing memory leaks.


366-378: LGTM: Button state management integrated

The GitHub button correctly uses the dynamic githubButtonText and githubButtonDisabled states to provide user feedback during the OAuth flow.

web/src/components/auth/LoginForm.jsx (1)

461-473: LGTM: Consistent implementation with RegisterForm

The GitHub button correctly implements the same dynamic state pattern as RegisterForm, providing consistent UX across login and registration flows.

Comment on lines +2113 to +2114
"正在跳转 GitHub...": "Redirecting to GitHub...",
"请求超时,请刷新页面后重新发起 GitHub 登录": "Request timed out, please refresh and restart GitHub login"

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.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

Polish the timeout copy; keep tone consistent with “Sign in”.

Recommend a clearer, two‑sentence phrasing:

-    "请求超时,请刷新页面后重新发起 GitHub 登录": "Request timed out, please refresh and restart GitHub login"
+    "请求超时,请刷新页面后重新发起 GitHub 登录": "Request timed out. Please refresh the page and try signing in with GitHub again."

Run to verify these keys exist in all locales and are referenced in UI:


🏁 Script executed:

#!/bin/bash
set -euo pipefail
keys=('正在跳转 GitHub...' '请求超时,请刷新页面后重新发起 GitHub 登录')
echo "Checking locale coverage…"
for f in web/src/i18n/locales/*.json; do
  for k in "${keys[@]}"; do
    jq -e --arg k "$k" '.translation[$k]' "$f" >/dev/null || echo "MISSING: $k -> $f"
  done
done
echo "Searching UI usages…"
rg -nP --type=ts --type=tsx --type=js --type=jsx -C2 "(正在跳转 GitHub\.\.\.|请求超时,请刷新页面后重新发起 GitHub 登录)" web/ || true

Length of output: 74


I see the locale coverage check passed (no MISSING messages), but the UI usage search needs adjustment. Let me retry with a corrected command:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Locale coverage (confirmed) ==="
echo "Keys found in all locale files ✓"

echo ""
echo "=== Searching UI usages ==="
rg -nP --type=ts --type=js --type=jsx -C2 "(正在跳转 GitHub|请求超时)" web/ || echo "No matches found in ts/js/jsx files"

echo ""
echo "=== Checking existing GitHub login patterns ==="
rg -nP --type=ts --type=js "sign.*in|Sign.*in|GitHub" web/src --max-count=5 -i || true

Length of output: 258


📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"正在跳转 GitHub...": "Redirecting to GitHub...",
"请求超时,请刷新页面后重新发起 GitHub 登录": "Request timed out, please refresh and restart GitHub login"
"正在跳转 GitHub...": "Redirecting to GitHub...",
"请求超时,请刷新页面后重新发起 GitHub 登录": "Request timed out. Please refresh the page and try signing in with GitHub again."
🤖 Prompt for AI Agents
In web/src/i18n/locales/en.json around lines 2113 to 2114, update the timeout
copy for consistency with other locales: replace the current value "Request
timed out, please refresh and restart GitHub login" with a more polished and
consistent phrase such as "Request timed out. Please refresh the page and try
signing in with GitHub again." Ensure the key remains unchanged and mirror this
wording across all locale files used by LoginForm.jsx and RegisterForm.jsx.

@Calcium-Ion
Calcium-Ion merged commit c133678 into QuantumNous:main Nov 19, 2025
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
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