[PR #4650] [MERGED] fix: respect errorCallbackURL in failed oauth flows #13753

Closed
opened 2026-04-13 09:07:44 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4650
Author: @frectonz
Created: 9/14/2025
Status: Merged
Merged: 9/16/2025
Merged by: @himself65

Base: canaryHead: fix/oauth-redirect-custom-error-url


📝 Commits (3)

  • d9d3541 fix: respect errorCallbackURL in failed oauth flows
  • 8e93635 chore: update variable name casing to baseURL instead of baseUrl
  • 03c6de3 fix: check that state exists before trying to parse it

📊 Changes

1 file changed (+17 additions, -14 deletions)

View changed files

📝 packages/better-auth/src/api/routes/callback.ts (+17 -14)

📄 Description

closes #1580


Summary by cubic

Respect the errorCallbackURL for failed OAuth callbacks so users land on the app’s custom error page. Also forwards error_description when provided.

  • Bug Fixes
    • Use errorCallbackURL from parsed state for provider errors, missing state, and missing code.
    • Centralize redirects via redirectOnError; builds URLs with URLSearchParams and preserves existing query strings, including error_description.
    • Reorder checks to parse state first so the custom error URL is available; keeps error logging.

🔄 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/4650 **Author:** [@frectonz](https://github.com/frectonz) **Created:** 9/14/2025 **Status:** ✅ Merged **Merged:** 9/16/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/oauth-redirect-custom-error-url` --- ### 📝 Commits (3) - [`d9d3541`](https://github.com/better-auth/better-auth/commit/d9d35417df6aaf1bb855421d9e7dc7ae1fde7333) fix: respect `errorCallbackURL` in failed oauth flows - [`8e93635`](https://github.com/better-auth/better-auth/commit/8e936357ed0c162dbff3d6c08aa804a56fa1ec0d) chore: update variable name casing to `baseURL` instead of `baseUrl` - [`03c6de3`](https://github.com/better-auth/better-auth/commit/03c6de390f91692751ad0b97a054d975a5fc7876) fix: check that state exists before trying to parse it ### 📊 Changes **1 file changed** (+17 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/callback.ts` (+17 -14) </details> ### 📄 Description closes #1580 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Respect the errorCallbackURL for failed OAuth callbacks so users land on the app’s custom error page. Also forwards error_description when provided. - **Bug Fixes** - Use errorCallbackURL from parsed state for provider errors, missing state, and missing code. - Centralize redirects via redirectOnError; builds URLs with URLSearchParams and preserves existing query strings, including error_description. - Reorder checks to parse state first so the custom error URL is available; keeps error logging. <!-- 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-13 09:07:44 -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#13753