[GH-ISSUE #4566] Support callback in onAPIError's errorURL #18616

Closed
opened 2026-04-15 17:10:15 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @CarrettaRiccardo on GitHub (Sep 10, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4566

Is this suited for github?

  • Yes, this is suited for github

Currently, onAPIError supports a string property called errorURL.

The path is returned when receiving an error in the authentication, and automatically appends some search parameters like error and error_description.

Describe the solution you'd like

It would be useful to support both string option as well as a customizable callback:

// errorURL: "/error", // <--- current usage
errorURL: ({ error, error_description }) => {
    if (error === "access_denied") 
        return "/denied";
    else 
        return "/error";
}

Describe alternatives you've considered

redirecting in another page/route based on the error query param, but it's not optimal

Additional context

No response

Originally created by @CarrettaRiccardo on GitHub (Sep 10, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4566 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Currently, `onAPIError` supports a string property called `errorURL`. The path is returned when receiving an error in the authentication, and automatically appends some search parameters like `error` and `error_description`. ### Describe the solution you'd like It would be useful to support both string option as well as a customizable `callback`: ```js // errorURL: "/error", // <--- current usage errorURL: ({ error, error_description }) => { if (error === "access_denied") return "/denied"; else return "/error"; } ``` ### Describe alternatives you've considered redirecting in another page/route based on the **error query param**, but it's not optimal ### Additional context _No response_
GiteaMirror added the lockedenhancement labels 2026-04-15 17:10:15 -05:00
Author
Owner

@GautamBytes commented on GitHub (Nov 1, 2025):

working on it , expect a pr soon!!

<!-- gh-comment-id:3475989431 --> @GautamBytes commented on GitHub (Nov 1, 2025): working on it , expect a pr soon!!
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 1, 2025):

You should move forward by adjusting the error handling so that the onAPIError.errorURL option accepts either a string or a function returning the redirect URL. In your PR you’ll need to update the type definitions and modify the OAuth and API error handlers to check if errorURL is a function—if so, invoke it with the error details before appending the standard query parameters—and fall back to the default string if not provided [1][2]. Also, please add tests for scenarios covering both static and dynamic error redirection, and update the documentation with usage examples. Let us know if you run into any issues during implementation.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3475989752 --> @better-auth-agent[bot] commented on GitHub (Nov 1, 2025): You should move forward by adjusting the error handling so that the onAPIError.errorURL option accepts either a string or a function returning the redirect URL. In your PR you’ll need to update the type definitions and modify the OAuth and API error handlers to check if errorURL is a function—if so, invoke it with the error details before appending the standard query parameters—and fall back to the default string if not provided [[1]](https://github.com/better-auth/better-auth/issues/4566)[[2]](https://github.com/better-auth/better-auth/issues/4356). Also, please add tests for scenarios covering both static and dynamic error redirection, and update the documentation with usage examples. Let us know if you run into any issues during implementation. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Jan 31, 2026):

Hi, @CarrettaRiccardo. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You requested enhancing the onAPIError feature to allow the errorURL option to accept a callback function for dynamic error URL determination.
  • GautamBytes is actively working on this enhancement and plans to submit a PR soon.
  • The maintainer advised updating type definitions, error handlers, tests, and documentation to support both string and function forms of errorURL.
  • I have offered guidance and resources to assist with the implementation.

Next Steps:

  • Please let me know if this issue is still relevant to the latest version of better-auth by commenting here to keep the discussion open.
  • Otherwise, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3828772708 --> @dosubot[bot] commented on GitHub (Jan 31, 2026): Hi, @CarrettaRiccardo. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You requested enhancing the `onAPIError` feature to allow the `errorURL` option to accept a callback function for dynamic error URL determination. - GautamBytes is actively working on this enhancement and plans to submit a PR soon. - The maintainer advised updating type definitions, error handlers, tests, and documentation to support both string and function forms of `errorURL`. - I have offered guidance and resources to assist with the implementation. **Next Steps:** - Please let me know if this issue is still relevant to the latest version of better-auth by commenting here to keep the discussion open. - Otherwise, this issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18616