[PR #5306] [CLOSED] feat: custom error urls #5915

Closed
opened 2026-03-13 12:41:11 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5306
Author: @ping-maxwell
Created: 10/14/2025
Status: Closed

Base: canaryHead: feat/custom-error-urls


📝 Commits (10+)

  • 4a4349e fix(create-adapter): disable transaction by default (#4750)
  • 71303f6 chore: lint
  • 05a7bd5 test: skip if adapter doesn't support transaction (#4753)
  • 5751036 chore: release v1.3.12
  • c03fd3a feat(last-login-method): update OAuth login method tracking for multiple auth type (#4693)
  • 8a4b30c feat: add returnHeaders to getSession (#3983)
  • 21bd4e6 fix(organization): remove autoCreateOnSignUp option as it's not implemented yet (#4755)
  • 8709af6 fix(passkey): remove email from query (#4740)
  • c151405 fix(client): baseURL is undefined for SSR (#4760)
  • 5394091 ci: fix release.yml (#4773)

📊 Changes

101 files changed (+4179 additions, -2881 deletions)

View changed files

📝 demo/expo-example/package.json (+3 -3)
📝 demo/nextjs/package.json (+2 -2)
docs/components/ask-ai-button.tsx (+52 -0)
📝 docs/content/docs/concepts/database.mdx (+22 -44)
📝 docs/content/docs/integrations/convex.mdx (+10 -10)
📝 e2e/smoke/test/fixtures/vite/vite.config.ts (+0 -1)
📝 package.json (+3 -2)
📝 packages/better-auth/package.json (+4 -3)
📝 packages/better-auth/src/__snapshots__/init.test.ts.snap (+1 -0)
📝 packages/better-auth/src/adapters/adapter-factory/index.ts (+1 -6)
📝 packages/better-auth/src/adapters/create-test-suite.ts (+2 -1)
📝 packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts (+56 -3)
📝 packages/better-auth/src/adapters/kysely-adapter/test/adapter.kysely.sqlite.test.ts (+1 -1)
📝 packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts (+1 -1)
📝 packages/better-auth/src/adapters/prisma-adapter/test/prisma.sqlite.test.ts (+2 -2)
📝 packages/better-auth/src/adapters/test-adapter.ts (+6 -0)
📝 packages/better-auth/src/adapters/tests/normal.ts (+50 -588)
📝 packages/better-auth/src/adapters/tests/number-id.ts (+1 -1)
📝 packages/better-auth/src/api/routes/account.test.ts (+35 -41)
📝 packages/better-auth/src/api/routes/callback.ts (+32 -27)

...and 80 more files

📄 Description

This PR allows you to pass a function to the onAPIError.errorURL to handle routing of different errors to different pages.

This PR also fixes OIDC & MCP plugin having incorrect error URL. It appends an additional /error making /api/auth/error/error?error=... which is incorrect.

linear: https://linear.app/better-auth/issue/ENG-114/feat-support-custom-callback-in-onapierrors-errorurl

issue: https://github.com/better-auth/better-auth/issues/4566


Summary by cubic

Adds support for custom error URLs via a function, letting apps route different API errors to specific pages. Centralizes error redirects across OAuth/SSO/OIDC using a new helper; addresses Linear ENG-114.

  • New Features

    • onAPIError.errorURL now accepts a string or a sync/async function (error, description, ctx) returning a URL.
    • Added context.getErrorURL to build the final redirect with defaults and encoded query params.
  • Refactors

    • Replaced manual error URL construction across OAuth2 callback, Generic OAuth, OIDC Provider, SSO, MCP, Admin, and OAuth Proxy to use getErrorURL.
    • Ensures consistent error and error_description handling and proper URL encoding.

🔄 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/5306 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 10/14/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/custom-error-urls` --- ### 📝 Commits (10+) - [`4a4349e`](https://github.com/better-auth/better-auth/commit/4a4349e26222d112a9250b5dee422a18c1536d54) fix(create-adapter): disable transaction by default (#4750) - [`71303f6`](https://github.com/better-auth/better-auth/commit/71303f6875d614eb1c8915365295ac61138e215c) chore: lint - [`05a7bd5`](https://github.com/better-auth/better-auth/commit/05a7bd58ced901dcc54694d2f95e1ed941dc4cf7) test: skip if adapter doesn't support transaction (#4753) - [`5751036`](https://github.com/better-auth/better-auth/commit/57510365a393bca2f6a37e50c43571651b121978) chore: release v1.3.12 - [`c03fd3a`](https://github.com/better-auth/better-auth/commit/c03fd3ac0dc8a3fee8d5b7514445c55135a9da06) feat(last-login-method): update OAuth login method tracking for multiple auth type (#4693) - [`8a4b30c`](https://github.com/better-auth/better-auth/commit/8a4b30c09493f40d310586b9d26a193ed53f19c5) feat: add `returnHeaders` to `getSession` (#3983) - [`21bd4e6`](https://github.com/better-auth/better-auth/commit/21bd4e68ba2d476a1d9d1b2f4604756ca7f53903) fix(organization): remove `autoCreateOnSignUp` option as it's not implemented yet (#4755) - [`8709af6`](https://github.com/better-auth/better-auth/commit/8709af6fe94a3e8e4e59967f50aa4c5b4fc9d2da) fix(passkey): remove `email` from query (#4740) - [`c151405`](https://github.com/better-auth/better-auth/commit/c15140549e1d314ee4836a4e24fdd7a2b2555ca9) fix(client): baseURL is undefined for SSR (#4760) - [`5394091`](https://github.com/better-auth/better-auth/commit/53940916a0f373842c48d86cf3369fe3e30fa044) ci: fix release.yml (#4773) ### 📊 Changes **101 files changed** (+4179 additions, -2881 deletions) <details> <summary>View changed files</summary> 📝 `demo/expo-example/package.json` (+3 -3) 📝 `demo/nextjs/package.json` (+2 -2) ➕ `docs/components/ask-ai-button.tsx` (+52 -0) 📝 `docs/content/docs/concepts/database.mdx` (+22 -44) 📝 `docs/content/docs/integrations/convex.mdx` (+10 -10) 📝 `e2e/smoke/test/fixtures/vite/vite.config.ts` (+0 -1) 📝 `package.json` (+3 -2) 📝 `packages/better-auth/package.json` (+4 -3) 📝 `packages/better-auth/src/__snapshots__/init.test.ts.snap` (+1 -0) 📝 `packages/better-auth/src/adapters/adapter-factory/index.ts` (+1 -6) 📝 `packages/better-auth/src/adapters/create-test-suite.ts` (+2 -1) 📝 `packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts` (+56 -3) 📝 `packages/better-auth/src/adapters/kysely-adapter/test/adapter.kysely.sqlite.test.ts` (+1 -1) 📝 `packages/better-auth/src/adapters/mongodb-adapter/mongodb-adapter.ts` (+1 -1) 📝 `packages/better-auth/src/adapters/prisma-adapter/test/prisma.sqlite.test.ts` (+2 -2) 📝 `packages/better-auth/src/adapters/test-adapter.ts` (+6 -0) 📝 `packages/better-auth/src/adapters/tests/normal.ts` (+50 -588) 📝 `packages/better-auth/src/adapters/tests/number-id.ts` (+1 -1) 📝 `packages/better-auth/src/api/routes/account.test.ts` (+35 -41) 📝 `packages/better-auth/src/api/routes/callback.ts` (+32 -27) _...and 80 more files_ </details> ### 📄 Description This PR allows you to pass a function to the `onAPIError.errorURL` to handle routing of different errors to different pages. This PR also fixes OIDC & MCP plugin having incorrect error URL. It appends an additional `/error` making `/api/auth/error/error?error=...` which is incorrect. linear: https://linear.app/better-auth/issue/ENG-114/feat-support-custom-callback-in-onapierrors-errorurl issue: https://github.com/better-auth/better-auth/issues/4566 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds support for custom error URLs via a function, letting apps route different API errors to specific pages. Centralizes error redirects across OAuth/SSO/OIDC using a new helper; addresses Linear ENG-114. - **New Features** - onAPIError.errorURL now accepts a string or a sync/async function (error, description, ctx) returning a URL. - Added context.getErrorURL to build the final redirect with defaults and encoded query params. - **Refactors** - Replaced manual error URL construction across OAuth2 callback, Generic OAuth, OIDC Provider, SSO, MCP, Admin, and OAuth Proxy to use getErrorURL. - Ensures consistent error and error_description handling and proper URL encoding. <!-- 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 12:41:11 -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#5915