[PR #7717] [CLOSED] OAuth proxy early redirect #7511

Closed
opened 2026-03-13 13:39:49 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7717
Author: @Bekacru
Created: 1/31/2026
Status: Closed

Base: canaryHead: cursor/oauth-proxy-early-redirect-dddd


📝 Commits (1)

  • f07c87d feat(oauth-proxy): add earlyRedirect option for separate database deployments

📊 Changes

4 files changed (+402 additions, -0 deletions)

View changed files

📝 docs/content/docs/plugins/oauth-proxy.mdx (+37 -0)
📝 packages/better-auth/src/plugins/oauth-proxy/index.ts (+125 -0)
📝 packages/better-auth/src/plugins/oauth-proxy/oauth-proxy.test.ts (+224 -0)
📝 packages/better-auth/src/plugins/oauth-proxy/types.ts (+16 -0)

📄 Description

Add earlyRedirect option to OAuth proxy to enable full callback processing on preview servers with separate databases.

The previous OAuth proxy flow processed the callback on the production server and then redirected to the preview server to set cookies. This caused issues when preview deployments used separate databases, as user and session data would be created in the production database, making the preview session invalid. The earlyRedirect option ensures the preview server handles the entire callback, creating data in its own database.


Slack Thread

Open in Cursor Open in Web


Summary by cubic

Add earlyRedirect to the OAuth proxy so preview servers process the full OAuth callback against their own database. This fixes invalid preview sessions when production and preview use different databases.

  • New Features

    • earlyRedirect option redirects the provider callback from production to the preview server before processing.
    • State package now includes earlyRedirect and previewBaseURL; preview runs the full callback and sets cookies.
    • After-hook skips proxy redirect when processing on preview (prevents double redirects).
    • Added tests and docs for “Early Redirect Mode”.
  • Migration

    • Enable earlyRedirect: true in the OAuth proxy config on both production and preview.
    • Use the same Better Auth secret on both servers.

Written for commit f07c87dfb5. Summary will update on new commits.


🔄 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/7717 **Author:** [@Bekacru](https://github.com/Bekacru) **Created:** 1/31/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `cursor/oauth-proxy-early-redirect-dddd` --- ### 📝 Commits (1) - [`f07c87d`](https://github.com/better-auth/better-auth/commit/f07c87dfb52049c83d60d4787cec61890c96a0af) feat(oauth-proxy): add earlyRedirect option for separate database deployments ### 📊 Changes **4 files changed** (+402 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/oauth-proxy.mdx` (+37 -0) 📝 `packages/better-auth/src/plugins/oauth-proxy/index.ts` (+125 -0) 📝 `packages/better-auth/src/plugins/oauth-proxy/oauth-proxy.test.ts` (+224 -0) 📝 `packages/better-auth/src/plugins/oauth-proxy/types.ts` (+16 -0) </details> ### 📄 Description Add `earlyRedirect` option to OAuth proxy to enable full callback processing on preview servers with separate databases. The previous OAuth proxy flow processed the callback on the production server and then redirected to the preview server to set cookies. This caused issues when preview deployments used separate databases, as user and session data would be created in the production database, making the preview session invalid. The `earlyRedirect` option ensures the preview server handles the entire callback, creating data in its own database. --- [Slack Thread](https://betterauth.slack.com/archives/C0A8B5BARUK/p1769820693965299?thread_ts=1769820693.965299&cid=C0A8B5BARUK) <a href="https://cursor.com/background-agent?bcId=bc-746ce3d0-6073-576f-b535-4dbab88c6940"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img alt="Open in Cursor" width="131" height="28" src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/agents?id=bc-746ce3d0-6073-576f-b535-4dbab88c6940"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a> <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add earlyRedirect to the OAuth proxy so preview servers process the full OAuth callback against their own database. This fixes invalid preview sessions when production and preview use different databases. - **New Features** - earlyRedirect option redirects the provider callback from production to the preview server before processing. - State package now includes earlyRedirect and previewBaseURL; preview runs the full callback and sets cookies. - After-hook skips proxy redirect when processing on preview (prevents double redirects). - Added tests and docs for “Early Redirect Mode”. - **Migration** - Enable earlyRedirect: true in the OAuth proxy config on both production and preview. - Use the same Better Auth secret on both servers. <sup>Written for commit f07c87dfb52049c83d60d4787cec61890c96a0af. Summary will update on new commits.</sup> <!-- 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-03-13 13:39:49 -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#7511