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

Closed
opened 2026-04-13 10:29:37 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/8580

State: closed
Merged: No


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.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/8580 **State:** closed **Merged:** No --- ## 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. -->
GiteaMirror added the pull-request label 2026-04-13 10:29:37 -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#16323