[PR #5523] [MERGED] fix: respect onAPIError.errorURL in OAuth callback flow #14306

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5523
Author: @GautamBytes
Created: 10/23/2025
Status: Merged
Merged: 10/23/2025
Merged by: @Bekacru

Base: canaryHead: fix/oauth-error-url


📝 Commits (2)

  • 6695e91 Respect in OAuth callback flow
  • 17506e5 Merge branch 'canary' into fix/oauth-error-url

📊 Changes

1 file changed (+2 additions, -1 deletions)

View changed files

📝 packages/better-auth/src/oauth2/state.ts (+2 -1)

📄 Description

This PR fixes issue #5518.

The parseState function in packages/better-auth/src/oauth2/state.ts was hardcoding the default error URL (/api/auth/error) instead of respecting the onAPIError.errorURL option from the user's configuration.

This change updates the logic to prioritize c.context.options.onAPIError?.errorURL before falling back to the default, ensuring the custom error URL is respected during the OAuth callback flow, as described in the issue.


Summary by cubic

Respect the configured onAPIError.errorURL in the OAuth callback so failed auth redirects to the app’s custom error page instead of always using /error. This fixes incorrect redirects during OAuth failures.

  • Bug Fixes
    • Updated parseState to prefer c.context.options.onAPIError?.errorURL, falling back to ${baseURL}/error.

🔄 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/5523 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 10/23/2025 **Status:** ✅ Merged **Merged:** 10/23/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/oauth-error-url` --- ### 📝 Commits (2) - [`6695e91`](https://github.com/better-auth/better-auth/commit/6695e913613408fb7817932e2c58e1c9cc70d365) Respect in OAuth callback flow - [`17506e5`](https://github.com/better-auth/better-auth/commit/17506e5f2e78f754ccb6e688915487febed522bb) Merge branch 'canary' into fix/oauth-error-url ### 📊 Changes **1 file changed** (+2 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/oauth2/state.ts` (+2 -1) </details> ### 📄 Description This PR fixes issue #5518. The `parseState` function in `packages/better-auth/src/oauth2/state.ts` was hardcoding the default error URL (`/api/auth/error`) instead of respecting the `onAPIError.errorURL` option from the user's configuration. This change updates the logic to prioritize `c.context.options.onAPIError?.errorURL` before falling back to the default, ensuring the custom error URL is respected during the OAuth callback flow, as described in the issue. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Respect the configured onAPIError.errorURL in the OAuth callback so failed auth redirects to the app’s custom error page instead of always using /error. This fixes incorrect redirects during OAuth failures. - **Bug Fixes** - Updated parseState to prefer c.context.options.onAPIError?.errorURL, falling back to `${baseURL}/error`. <!-- 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:24:25 -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#14306