[PR #4819] [CLOSED] fix(oauth): proxy Multi-Domain Redirect Issue #22495

Closed
opened 2026-04-15 21:05:13 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4819
Author: @nehaaprasad
Created: 9/22/2025
Status: Closed

Base: canaryHead: fix/oauth-url-redirect


📝 Commits (2)

  • 9230058 fix: resolve oauth-proxy inconsistent URL handling in multi-domain setups
  • 955e19a test: update oauth-proxy tests for new multi-domain behavior

📊 Changes

2 files changed (+19 additions, -11 deletions)

View changed files

📝 packages/better-auth/src/plugins/oauth-proxy/index.ts (+17 -10)
📝 packages/better-auth/src/plugins/oauth-proxy/oauth-proxy.test.ts (+2 -1)

📄 Description

Description:

- Fix inconsistent URL handling in oauth-proxy plugin for multi-domain setups

**Problem:**
- Users starting OAuth flow on baseURL (myapp.com) were redirected to productionURL (login.myapp.com) after login instead of staying on original domain
- Inconsistent use of baseURL vs productionURL between before/after hooks
- Callback URLs resolved relative to wrong domain in multi-domain environments

**Solution:**
- Updated after hook to use productionURL consistently with before hook  
- Preserve original domain context by passing originalOrigin parameter
- Improve proxy logic for better multi-domain support
- Clean up unnecessary comments for better code readability

**Impact:**
Users now correctly redirected back to their starting domain (myapp.com, tenant1.myapp.com, etc.) after OAuth login, resolving the multi-domain setup issue.

Related Issue: #4815 (OAuth Proxy Multi-Domain Redirect Bug)

Files Changed:

  • packages/better-auth/src/plugins/oauth-proxy/index.ts - Core fix
  • packages/better-auth/src/plugins/oauth-proxy/oauth-proxy.test.ts - Test updates

Summary by cubic

Fixes inconsistent URL handling in oauth-proxy for multi-domain setups so users return to the domain where they started OAuth. Addresses #4815.

  • Bug Fixes
    • Use productionURL consistently across before/after hooks; fallback to baseURL when unset.
    • Preserve starting domain via originalOrigin and build absolute redirects when callbackURL is relative.
    • Improve skip logic to avoid proxying when origins already match; update tests for the new behavior.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/4819 **Author:** [@nehaaprasad](https://github.com/nehaaprasad) **Created:** 9/22/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/oauth-url-redirect` --- ### 📝 Commits (2) - [`9230058`](https://github.com/better-auth/better-auth/commit/9230058b5a28de5390f2b7a892e269c56d74d4f6) fix: resolve oauth-proxy inconsistent URL handling in multi-domain setups - [`955e19a`](https://github.com/better-auth/better-auth/commit/955e19aee7d67abb78963205e8268b30192ac9f9) test: update oauth-proxy tests for new multi-domain behavior ### 📊 Changes **2 files changed** (+19 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/oauth-proxy/index.ts` (+17 -10) 📝 `packages/better-auth/src/plugins/oauth-proxy/oauth-proxy.test.ts` (+2 -1) </details> ### 📄 Description **Description:** ``` - Fix inconsistent URL handling in oauth-proxy plugin for multi-domain setups **Problem:** - Users starting OAuth flow on baseURL (myapp.com) were redirected to productionURL (login.myapp.com) after login instead of staying on original domain - Inconsistent use of baseURL vs productionURL between before/after hooks - Callback URLs resolved relative to wrong domain in multi-domain environments **Solution:** - Updated after hook to use productionURL consistently with before hook - Preserve original domain context by passing originalOrigin parameter - Improve proxy logic for better multi-domain support - Clean up unnecessary comments for better code readability **Impact:** Users now correctly redirected back to their starting domain (myapp.com, tenant1.myapp.com, etc.) after OAuth login, resolving the multi-domain setup issue. ``` **Related Issue:** #4815 (OAuth Proxy Multi-Domain Redirect Bug) **Files Changed:** - `packages/better-auth/src/plugins/oauth-proxy/index.ts` - Core fix - `packages/better-auth/src/plugins/oauth-proxy/oauth-proxy.test.ts` - Test updates <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes inconsistent URL handling in oauth-proxy for multi-domain setups so users return to the domain where they started OAuth. Addresses #4815. - **Bug Fixes** - Use productionURL consistently across before/after hooks; fallback to baseURL when unset. - Preserve starting domain via originalOrigin and build absolute redirects when callbackURL is relative. - Improve skip logic to avoid proxying when origins already match; update tests for the new behavior. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 21:05:13 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#22495