[PR #8571] feat(magic-link): add request metadata to sendMagicLink #16317

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

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

State: closed
Merged: Yes


Summary

  • add optional metadata to signIn.magicLink
  • forward request metadata to the magic-link plugin sendMagicLink callback
  • add runtime, client type, and docs coverage for the new field

Why

This lets callers attach request-scoped metadata when requesting a magic link so server implementations can use it inside sendMagicLink without changing verification, session, or user behavior.

API changes

  • signIn.magicLink now accepts metadata?: Record<string, any>
  • sendMagicLink now receives metadata?: Record<string, any> in its first argument

Behavior

  • metadata is send-only
  • metadata is not stored in the verification record
  • metadata is not added to the magic link URL
  • metadata does not affect verification, session creation, or user creation

Validation

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

Breaking changes

None.


Summary by cubic

Add optional request-scoped metadata to signIn.magicLink and forward it to the sendMagicLink callback. This enables servers to use extra context (e.g., inviteId) when sending the email without changing verification or session behavior.

  • New Features
    • signIn.magicLink now accepts metadata?: Record<string, any> and passes it to sendMagicLink({ email, url, token, metadata }).
    • Validated via schema updates and tested for type inference and forwarding in packages/better-auth.
    • Docs updated to include metadata in examples and API reference.
    • Metadata is send-only: not stored, not added to the URL, and does not affect verification, session, or user creation.

Written for commit 2062383f02. Summary will update on new commits.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/8571 **State:** closed **Merged:** Yes --- ## Summary - add optional `metadata` to `signIn.magicLink` - forward request metadata to the magic-link plugin `sendMagicLink` callback - add runtime, client type, and docs coverage for the new field ## Why This lets callers attach request-scoped metadata when requesting a magic link so server implementations can use it inside `sendMagicLink` without changing verification, session, or user behavior. ## API changes - `signIn.magicLink` now accepts `metadata?: Record<string, any>` - `sendMagicLink` now receives `metadata?: Record<string, any>` in its first argument ## Behavior - metadata is send-only - metadata is not stored in the verification record - metadata is not added to the magic link URL - metadata does not affect verification, session creation, or user creation ## Validation - `pnpm build` - `pnpm lint` - `pnpm typecheck` - `pnpm --filter better-auth exec vitest run src/client/client.test.ts` - `pnpm --filter better-auth exec vitest run src/plugins/magic-link/magic-link.test.ts` ## Breaking changes None. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add optional request-scoped `metadata` to `signIn.magicLink` and forward it to the `sendMagicLink` callback. This enables servers to use extra context (e.g., `inviteId`) when sending the email without changing verification or session behavior. - **New Features** - `signIn.magicLink` now accepts `metadata?: Record<string, any>` and passes it to `sendMagicLink({ email, url, token, metadata })`. - Validated via schema updates and tested for type inference and forwarding in `packages/better-auth`. - Docs updated to include `metadata` in examples and API reference. - Metadata is send-only: not stored, not added to the URL, and does not affect verification, session, or user creation. <sup>Written for commit 2062383f0291e92fa04cbae7ee6319f02e62e174. 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:31 -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#16317