[PR #6330] [CLOSED] fix(userName-Plugin) implement-callback-url-handling #6596

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6330
Author: @Ridhim-RR
Created: 11/26/2025
Status: Closed

Base: canaryHead: fix/callback-url-usernameplugin


📝 Commits (5)

  • b932764 fix(userName-Plugin) implement-callback-url-handling
  • 6e4449d chore: Implement originCheck middleware and diff credentials in the test cases
  • f75c059 Update packages/better-auth/src/plugins/username/index.ts
  • ee8a952 Merge branch 'canary' into fix/callback-url-usernameplugin
  • d0f8865 Merge branch 'canary' into fix/callback-url-usernameplugin

📊 Changes

2 files changed (+48 additions, -1 deletions)

View changed files

📝 packages/better-auth/src/plugins/username/index.ts (+6 -1)
📝 packages/better-auth/src/plugins/username/username.test.ts (+42 -0)

📄 Description

Closes #6297

This PR implements the handling of the callback URL in the Username plugin.

Changes:

  • In the index.ts file within the sign-in with Username flow, implement handling of the callback URL if it is sent from the frontend.
  • If no callback URL is provided, fall back to the root path "/".
  • The response now includes url field which will include the callback url along with token and duser Information.

Updated Response

return ctx.json({
  url: callbackURL,
  token: session.token,
  user: {
    id: user.id,
    email: user.email,
    emailVerified: user.emailVerified,
    username: user.username,
    displayUsername: user.displayUsername,
    name: user.name,
    image: user.image,
    createdAt: user.createdAt,
    updatedAt: user.updatedAt,
  },
});

Previous Response

return ctx.json({
  token: session.token,
  user: {
    id: user.id,
    email: user.email,
    emailVerified: user.emailVerified,
    username: user.username,
    displayUsername: user.displayUsername,
    name: user.name,
    image: user.image,
    createdAt: user.createdAt,
    updatedAt: user.updatedAt,
  },
});

  • Added two test cases in username.test.ts:
    - One to verify that, if a URL is provided in the request body, it is returned in the response.
    - Another to check that, if no URL is provided, the fallback URL ("/") is sent back.

Summary by cubic

Adds callback URL handling to the Username sign-in flow, validates its origin, and returns it as url in the response for post-auth redirects. If no callbackURL is provided, the response defaults to "/" (addresses #6297).

Written for commit d0f8865e3f. 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/6330 **Author:** [@Ridhim-RR](https://github.com/Ridhim-RR) **Created:** 11/26/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/callback-url-usernameplugin` --- ### 📝 Commits (5) - [`b932764`](https://github.com/better-auth/better-auth/commit/b932764bcdec692ec51631c9509d68bf4ac36a8b) fix(userName-Plugin) implement-callback-url-handling - [`6e4449d`](https://github.com/better-auth/better-auth/commit/6e4449d3f870f1088982f75c08914fb64e54f6a4) chore: Implement originCheck middleware and diff credentials in the test cases - [`f75c059`](https://github.com/better-auth/better-auth/commit/f75c0593b4d2c03d580f3928fed9d89a5004e551) Update packages/better-auth/src/plugins/username/index.ts - [`ee8a952`](https://github.com/better-auth/better-auth/commit/ee8a9526d175c526c0d8706de555dd94b6de357f) Merge branch 'canary' into fix/callback-url-usernameplugin - [`d0f8865`](https://github.com/better-auth/better-auth/commit/d0f8865e3f50f27179eec6af4436a604c75658e7) Merge branch 'canary' into fix/callback-url-usernameplugin ### 📊 Changes **2 files changed** (+48 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/username/index.ts` (+6 -1) 📝 `packages/better-auth/src/plugins/username/username.test.ts` (+42 -0) </details> ### 📄 Description **Closes** #6297 This PR implements the handling of the callback URL in the Username plugin. **Changes**: - In the index.ts file within the sign-in with Username flow, implement handling of the callback URL if it is sent from the frontend. - If no callback URL is provided, fall back to the root path "/". - The response now includes url field which will include the callback url along with token and duser Information. Updated Response ``` return ctx.json({ url: callbackURL, token: session.token, user: { id: user.id, email: user.email, emailVerified: user.emailVerified, username: user.username, displayUsername: user.displayUsername, name: user.name, image: user.image, createdAt: user.createdAt, updatedAt: user.updatedAt, }, }); ``` Previous Response ``` return ctx.json({ token: session.token, user: { id: user.id, email: user.email, emailVerified: user.emailVerified, username: user.username, displayUsername: user.displayUsername, name: user.name, image: user.image, createdAt: user.createdAt, updatedAt: user.updatedAt, }, }); ``` - Added two test cases in username.test.ts: - One to verify that, if a URL is provided in the request body, it is returned in the response. - Another to check that, if no URL is provided, the fallback URL ("/") is sent back. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds callback URL handling to the Username sign-in flow, validates its origin, and returns it as url in the response for post-auth redirects. If no callbackURL is provided, the response defaults to "/" (addresses #6297). <sup>Written for commit d0f8865e3f50f27179eec6af4436a604c75658e7. 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:04:43 -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#6596