[PR #6383] [MERGED] fix(magic-link): handle query params in errorCallbackUrl #6629

Closed
opened 2026-03-13 13:06:05 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6383
Author: @martinriviere
Created: 11/28/2025
Status: Merged
Merged: 12/9/2025
Merged by: @Bekacru

Base: canaryHead: fix/magic-link-error-callback-url-query-params


📝 Commits (2)

  • fa12763 fix: handle query params in errorCallbackUrl
  • cfa9e5f test: add magic link test for errorCallbackUrl

📊 Changes

2 files changed (+42 additions, -17 deletions)

View changed files

📝 packages/better-auth/src/plugins/magic-link/index.ts (+12 -17)
📝 packages/better-auth/src/plugins/magic-link/magic-link.test.ts (+30 -0)

📄 Description

Description

During magic link verification, if the errorCallbackUrl contains query params, it could lead to invalid url in case of verification error, like https://myapp.com/error-page?foo=bar?error=EXPIRED_TOKEN.

This PR fixes that issue, and also clean some dead code (toRedirectTo variable which was no longer used).


Summary by cubic

Fixes errorCallbackUrl handling during magic link verification so error params are appended correctly without breaking URLs. Also removes unused code.

  • Bug Fixes

    • Build errorCallbackURL with URL and add the error via searchParams to avoid double “?” and malformed redirects.
  • Refactors

    • Introduced redirectWithError helper to centralize error redirects.
    • Removed unused toRedirectTo variable.

Written for commit cfa9e5f15a. Summary will update automatically 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/6383 **Author:** [@martinriviere](https://github.com/martinriviere) **Created:** 11/28/2025 **Status:** ✅ Merged **Merged:** 12/9/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/magic-link-error-callback-url-query-params` --- ### 📝 Commits (2) - [`fa12763`](https://github.com/better-auth/better-auth/commit/fa127639924297b9dc95f0f8e39d535b2fa269c1) fix: handle query params in errorCallbackUrl - [`cfa9e5f`](https://github.com/better-auth/better-auth/commit/cfa9e5f15a10a9624599949421492a0c8186ce58) test: add magic link test for errorCallbackUrl ### 📊 Changes **2 files changed** (+42 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/magic-link/index.ts` (+12 -17) 📝 `packages/better-auth/src/plugins/magic-link/magic-link.test.ts` (+30 -0) </details> ### 📄 Description ## Description During magic link verification, if the `errorCallbackUrl` contains query params, it could lead to invalid url in case of verification error, like `https://myapp.com/error-page?foo=bar?error=EXPIRED_TOKEN`. This PR fixes that issue, and also clean some dead code (`toRedirectTo` variable which was no longer used). <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes errorCallbackUrl handling during magic link verification so error params are appended correctly without breaking URLs. Also removes unused code. - **Bug Fixes** - Build errorCallbackURL with URL and add the error via searchParams to avoid double “?” and malformed redirects. - **Refactors** - Introduced redirectWithError helper to centralize error redirects. - Removed unused toRedirectTo variable. <sup>Written for commit cfa9e5f15a10a9624599949421492a0c8186ce58. Summary will update automatically 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-03-13 13:06:05 -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#6629