[PR #7716] [CLOSED] fix(oauth-provider): detect fetch requests using sec-fetch-mode header #24411

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

📋 Pull Request Information

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

Base: mainHead: 2026-01-31/fix/oauth-provider-redirect


📝 Commits (2)

  • 3c9d21c fix: detect fetch requests using sec-fetch-mode header
  • 08e3573 test: add cases for handleRedirect

📊 Changes

2 files changed (+131 additions, -3 deletions)

View changed files

📝 packages/oauth-provider/src/authorize.test.ts (+127 -0)
📝 packages/oauth-provider/src/authorize.ts (+4 -3)

📄 Description

Note

Reference: https://github.com/better-auth/better-auth/blob/canary/packages/better-auth/src/plugins/oidc-provider/authorize.ts#L31


Summary by cubic

Detects fetch-based OAuth authorize requests using the sec-fetch-mode header and returns a JSON redirect payload, while keeping 302 redirects for normal navigation. This makes SPA/fetch clients handle redirects cleanly.

  • Bug Fixes
    • handleRedirect returns JSON when sec-fetch-mode=cors or Accept: application/json is present.
    • Falls back to 302 redirect when no fetch headers are set.
    • Added tests covering both JSON and 302 behaviors.

Written for commit 08e3573b6c. 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/7716 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 1/31/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `2026-01-31/fix/oauth-provider-redirect` --- ### 📝 Commits (2) - [`3c9d21c`](https://github.com/better-auth/better-auth/commit/3c9d21c1c1c06cf11a766105291e9f2e8725b5d2) fix: detect fetch requests using sec-fetch-mode header - [`08e3573`](https://github.com/better-auth/better-auth/commit/08e3573b6cd771d63c4360bba3f437ea3fb92539) test: add cases for handleRedirect ### 📊 Changes **2 files changed** (+131 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/oauth-provider/src/authorize.test.ts` (+127 -0) 📝 `packages/oauth-provider/src/authorize.ts` (+4 -3) </details> ### 📄 Description > [!NOTE] > Reference: https://github.com/better-auth/better-auth/blob/canary/packages/better-auth/src/plugins/oidc-provider/authorize.ts#L31 - Closes https://github.com/better-auth/better-auth/issues/7710 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Detects fetch-based OAuth authorize requests using the sec-fetch-mode header and returns a JSON redirect payload, while keeping 302 redirects for normal navigation. This makes SPA/fetch clients handle redirects cleanly. - **Bug Fixes** - handleRedirect returns JSON when sec-fetch-mode=cors or Accept: application/json is present. - Falls back to 302 redirect when no fetch headers are set. - Added tests covering both JSON and 302 behaviors. <sup>Written for commit 08e3573b6cd771d63c4360bba3f437ea3fb92539. 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-04-15 22:21:29 -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#24411