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

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8571
Author: @mrgrauel
Created: 3/12/2026
Status: Merged
Merged: 3/12/2026
Merged by: @himself65

Base: canaryHead: feat/add-metadata-to-magic-link


📝 Commits (1)

  • 2062383 feat(magic-link): add request metadata to sendMagicLink

📊 Changes

4 files changed (+64 additions, -2 deletions)

View changed files

📝 docs/content/docs/plugins/magic-link.mdx (+6 -1)
📝 packages/better-auth/src/client/client.test.ts (+31 -0)
📝 packages/better-auth/src/plugins/magic-link/index.ts (+9 -1)
📝 packages/better-auth/src/plugins/magic-link/magic-link.test.ts (+18 -0)

📄 Description

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.


🔄 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/8571 **Author:** [@mrgrauel](https://github.com/mrgrauel) **Created:** 3/12/2026 **Status:** ✅ Merged **Merged:** 3/12/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `feat/add-metadata-to-magic-link` --- ### 📝 Commits (1) - [`2062383`](https://github.com/better-auth/better-auth/commit/2062383f0291e92fa04cbae7ee6319f02e62e174) feat(magic-link): add request metadata to sendMagicLink ### 📊 Changes **4 files changed** (+64 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/magic-link.mdx` (+6 -1) 📝 `packages/better-auth/src/client/client.test.ts` (+31 -0) 📝 `packages/better-auth/src/plugins/magic-link/index.ts` (+9 -1) 📝 `packages/better-auth/src/plugins/magic-link/magic-link.test.ts` (+18 -0) </details> ### 📄 Description ## 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. --> --- <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:05 -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#8071