[PR #8580] [CLOSED] feat(magic-link): add opt-in server-only token return #8077

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8580
Author: @mrgrauel
Created: 3/12/2026
Status: Closed

Base: canaryHead: feat/add-url-token-to-magic-link-return


📝 Commits (2)

  • 1f4083d feat(magic-link): return url and token from sign-in
  • fe54166 fix(magic-link): keep token return server-only

📊 Changes

3 files changed (+325 additions, -57 deletions)

View changed files

📝 docs/content/docs/plugins/magic-link.mdx (+28 -0)
📝 packages/better-auth/src/plugins/magic-link/index.ts (+108 -39)
📝 packages/better-auth/src/plugins/magic-link/magic-link.test.ts (+189 -18)

📄 Description

Summary

  • restore the public signIn.magicLink HTTP response to status-only so the raw token never reaches browser clients
  • add an explicit returnToken option and a server-only auth.api.signInMagicLinkServer() helper for trusted server-side workflows
  • update docs and tests with the security warning, opt-in server-only usage, and hashed/custom storage coverage

Validation

  • pnpm --filter better-auth exec vitest run src/plugins/magic-link/magic-link.test.ts

Notes

  • authClient.signIn.magicLink() and POST /sign-in/magic-link still return only { status: true }
  • when returnToken: true is enabled, auth.api.signInMagicLinkServer() returns the generated url and raw token
  • the raw token remains opt-in and server-only; it is never added to the public HTTP/OpenAPI contract
  • supersedes [GH-ISSUE #1060] Generate ID before invoking the before hook (#8572)

Summary by cubic

Lock down magic-link sign-in so public endpoints return status-only, and add an opt-in server-only helper that can return the URL and raw token for trusted workflows. This prevents the token from reaching browsers while enabling secure server-side use cases.

  • New Features

    • Added returnToken option (default false).
    • Introduced server-only auth.api.signInMagicLinkServer that returns { status }, or { status, url, token } when returnToken: true.
    • Updated docs with guidance and warnings; expanded tests (including hashed/custom token storage).
  • Bug Fixes

    • Restored signIn.magicLink and POST /sign-in/magic-link to return only { status: true }.
    • Kept the token out of the HTTP/OpenAPI contract; openAPI schema requires only status and has no token or url.
    • Token remains in the out-of-band channel handled by sendMagicLink.

Written for commit fe54166862. Summary will update 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/8580 **Author:** [@mrgrauel](https://github.com/mrgrauel) **Created:** 3/12/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/add-url-token-to-magic-link-return` --- ### 📝 Commits (2) - [`1f4083d`](https://github.com/better-auth/better-auth/commit/1f4083dfc80fa72db9cac0fa0764db2992286d2e) feat(magic-link): return url and token from sign-in - [`fe54166`](https://github.com/better-auth/better-auth/commit/fe5416686234916074f6067cd71091437b0ce319) fix(magic-link): keep token return server-only ### 📊 Changes **3 files changed** (+325 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/magic-link.mdx` (+28 -0) 📝 `packages/better-auth/src/plugins/magic-link/index.ts` (+108 -39) 📝 `packages/better-auth/src/plugins/magic-link/magic-link.test.ts` (+189 -18) </details> ### 📄 Description ## Summary - restore the public `signIn.magicLink` HTTP response to status-only so the raw token never reaches browser clients - add an explicit `returnToken` option and a server-only `auth.api.signInMagicLinkServer()` helper for trusted server-side workflows - update docs and tests with the security warning, opt-in server-only usage, and hashed/custom storage coverage ## Validation - `pnpm --filter better-auth exec vitest run src/plugins/magic-link/magic-link.test.ts` ## Notes - `authClient.signIn.magicLink()` and `POST /sign-in/magic-link` still return only `{ status: true }` - when `returnToken: true` is enabled, `auth.api.signInMagicLinkServer()` returns the generated `url` and raw `token` - the raw token remains opt-in and server-only; it is never added to the public HTTP/OpenAPI contract - supersedes #8572 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Lock down magic-link sign-in so public endpoints return status-only, and add an opt-in server-only helper that can return the URL and raw token for trusted workflows. This prevents the token from reaching browsers while enabling secure server-side use cases. - **New Features** - Added `returnToken` option (default `false`). - Introduced server-only `auth.api.signInMagicLinkServer` that returns `{ status }`, or `{ status, url, token }` when `returnToken: true`. - Updated docs with guidance and warnings; expanded tests (including hashed/custom token storage). - **Bug Fixes** - Restored `signIn.magicLink` and `POST /sign-in/magic-link` to return only `{ status: true }`. - Kept the token out of the HTTP/OpenAPI contract; `openAPI` schema requires only `status` and has no `token` or `url`. - Token remains in the out-of-band channel handled by `sendMagicLink`. <sup>Written for commit fe5416686234916074f6067cd71091437b0ce319. Summary will update 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:59:20 -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#8077