signUp.email() does not handle the callbackURL correctly if there is a search param in callbackURL #382

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

Originally created by @bfovez on GitHub (Dec 10, 2024).

Describe the bug
signUp.email() callbackURL does not handle correctly if there is a search param and the token is wrong.
Instead of gracefully adding to search param, it seems to merely add the string "?error=invalid_token" at the end.

To Reproduce
Call signUp.email() with a callbackURL with a search param.
Say: signUp.email({callbackURL:"http://localhost:5173/test?key=value"})

The url for email verification is then:
http://localhost:5173/api/auth/verify-email?token=xx&callbackURL=http://localhost:5173/auth/sign-in?key=value
Note that the callbackURL search param is not properly encoded (by the way, not specifically related to this bug).

The browser then redirects to
http://localhost:5173/auth/sign-in?email=key=value?error=invalid_token
instead of
http://localhost:5173/auth/sign-in?email=key=value&error=invalid_token

Therefore, the URL is invalid.

Expected behavior
Not:

callbackURL + '?error=invalid_token'

but

url = new URL(callbackURL)
url.searchParams.set('error', 'invalid_token')
return url.href
Originally created by @bfovez on GitHub (Dec 10, 2024). **Describe the bug** `signUp.email()` callbackURL does not handle correctly if there is a search param and the token is wrong. Instead of gracefully adding to search param, it seems to merely add the string "?error=invalid_token" at the end. **To Reproduce** Call `signUp.email()` with a callbackURL with a search param. Say: `signUp.email({callbackURL:"http://localhost:5173/test?key=value"})` The url for email verification is then: http://localhost:5173/api/auth/verify-email?token=xx&callbackURL=http://localhost:5173/auth/sign-in?key=value Note that the `callbackURL` search param is not properly encoded (by the way, not specifically related to this bug). The browser then redirects to http://localhost:5173/auth/sign-in?email=key=value?error=invalid_token instead of http://localhost:5173/auth/sign-in?email=key=value&error=invalid_token Therefore, the URL is invalid. **Expected behavior** Not: ```ts callbackURL + '?error=invalid_token' ``` but ```ts url = new URL(callbackURL) url.searchParams.set('error', 'invalid_token') return url.href ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#382