Skip to content

fix(auth): add timeout handling for OAuth fetch requests - #220

Merged
yash-pouranik merged 2 commits into
geturbackend:mainfrom
udaycodespace:fix/oauth-fetch-timeout-208
May 27, 2026
Merged

fix(auth): add timeout handling for OAuth fetch requests#220
yash-pouranik merged 2 commits into
geturbackend:mainfrom
udaycodespace:fix/oauth-fetch-timeout-208

Conversation

@udaycodespace

@udaycodespace udaycodespace commented May 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #208

🛠️ Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)

🧪 Testing & Validation

Backend Verification:

  • Verified the updated OAuth flow logic locally.
  • Confirmed timeout cleanup and graceful abort handling.

Frontend Verification:

  • Not applicable

🔍 Proof of Work

  • Added timeout handling to outbound OAuth fetch requests in auth.controller.js
  • Used AbortController to prevent long-running external requests
  • Added timeout cleanup using clearTimeout
  • Preserved the existing OAuth/authentication flow behavior
  • Limited changes to a single backend controller file

✅ Checklist

  • My code follows the code style of this project.
  • I have performed a self-review of my code.
  • My changes generate no new warnings or errors.

Built with ❤️ for urBackend.

Summary by CodeRabbit

  • Bug Fixes
    • Added timeout protection for OAuth requests to prevent indefinite hangs and provide clearer error messaging during timeout scenarios.
    • Improved error handling for authentication failures with enhanced fallback error message derivation.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@udaycodespace, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 43 minutes and 26 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 471d10ab-2eb1-4731-89c5-e1a53deb9260

📥 Commits

Reviewing files that changed from the base of the PR and between 8250e47 and e5bf0a2.

📒 Files selected for processing (1)
  • apps/dashboard-api/src/controllers/auth.controller.js
📝 Walkthrough

Walkthrough

Added OAuth-specific request timeout handling to the authentication controller's shared fetchJson helper. A new constant enforces timeout limits via AbortController, automatically aborting hung requests and throwing a deterministic timeout error while preserving existing JSON parsing and error-mapping behavior.

Changes

OAuth Request Timeout Protection

Layer / File(s) Summary
OAuth timeout enforcement via AbortController
apps/dashboard-api/src/controllers/auth.controller.js
Introduced OAUTH_FETCH_TIMEOUT_MS constant and modified fetchJson helper to wrap fetch calls with AbortController and setTimeout. Hung requests now abort gracefully and throw a deterministic "OAuth request timed out." error on abort; JSON payload parsing and non-OK error message selection logic remain unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Poem

🐰 A rabbit guards the warren gate,
No request lingers, no hanging wait—
With timeout's shield and abort's quick hand,
OAuth flows swift 'cross the land!
No provider delays our retreat, ⏱️✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding timeout handling for OAuth fetch requests, which accurately reflects the core modification in the auth controller.
Linked Issues check ✅ Passed The PR addresses all requirements from issue #208: adds AbortController timeout handling to OAuth fetch requests, aborts long-running requests, clears timers, and preserves existing auth flow behavior.
Out of Scope Changes check ✅ Passed All changes are scoped to the auth.controller.js file and directly address the timeout handling requirement from issue #208; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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

@udaycodespace

udaycodespace commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

@yash-pouranik Applied lightweight timeout protection to the OAuth fetch helper using AbortController. Added timeout cleanup and graceful abort handling without changing the existing auth flow.

@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 `@apps/dashboard-api/src/controllers/auth.controller.js`:
- Around line 101-107: Replace the raw Error throws in the response handling
blocks (the if (!response.ok) branch and the similar block at lines ~111-115)
with AppError instances: construct an AppError using the resolved message
(payload?.error_description || payload?.error || payload?.message ||
defaultMessage), set a suitable HTTP statusCode derived from response.status or
a default like 502, and include the original payload/response details as
non-sensitive context (e.g., in a meta/cause property) so controller error
middleware can handle it consistently; update imports to ensure AppError is
available in this file.
- Line 98: The fetch call allows options.signal to override the timeout
controller, so the timeout can be bypassed; change the argument order so the
controller's signal wins (pass options first and controller.signal last) when
calling fetch in the auth controller (the line with controller and options used
in the fetch call), and ensure you handle the case where options is undefined
before merging so the controller.signal is always applied.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6638bcec-68d8-4c61-9b81-95c11f91e5ca

📥 Commits

Reviewing files that changed from the base of the PR and between 6ebd300 and 8250e47.

📒 Files selected for processing (1)
  • apps/dashboard-api/src/controllers/auth.controller.js

Comment thread apps/dashboard-api/src/controllers/auth.controller.js Outdated
Comment thread apps/dashboard-api/src/controllers/auth.controller.js Outdated
@udaycodespace
udaycodespace force-pushed the fix/oauth-fetch-timeout-208 branch from 8250e47 to 120a5f0 Compare May 27, 2026 06:03
resetPasswordSchema,
verifyOtpSchema
} = require("@urbackend/common");
const AppError = require("@urbackend/common/src/utils/AppError");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not the standard to require the common package, please follow the current code practices, like in line 16, @udaycodespace

Comment thread apps/dashboard-api/src/controllers/auth.controller.js
@udaycodespace

Copy link
Copy Markdown
Contributor Author

@yash-pouranik fixed the import part as well 👍

  • About the timeout flow: when controller.abort() triggers, the fetch promise throws an AbortError.
  • It doesn’t automatically send a 408 response. In our case we catch it inside fetchJson() and convert it into an AppError(504) which then goes through the existing OAuth error/redirect flow.

@yash-pouranik

Copy link
Copy Markdown
Member

Ok got it

@yash-pouranik
yash-pouranik merged commit 48ac0ac into geturbackend:main May 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] Missing timeout handling for outbound fetch requests in OAuth flow

2 participants