[PR #8586] feat(magic-link): add server-only generateMagicLink API #24981

Open
opened 2026-04-15 22:40:13 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8586
Author: @mrgrauel
Created: 3/13/2026
Status: 🔄 Open

Base: nextHead: feat/expose-magic-link-token


📝 Commits (10+)

  • 3be60af feat(magic-link): add server-only generateMagicLink API
  • 4e34060 fix(magic-link): require headers for generateMagicLink
  • a4a196f test(magic-link): document server parity for generateMagicLink
  • d5fd7a1 fix(api): preserve declared auth endpoint paths
  • d20f92b docs(magic-link): use APIMethod for generateMagicLink
  • 8d82ca8 refactor(magic-link): clean up type exports in magic link plugin
  • c931983 test(api): add test for fallback path in pathless endpoints
  • c69cfb4 docs(magic-link): clarify response structure for signInMagicLink and related endpoints
  • 09d4de6 Merge branch 'main' into feat/expose-magic-link-token
  • 7c9ac86 docs(magic-link): update formatting in magic link documentation

📊 Changes

6 files changed (+473 additions, -45 deletions)

View changed files

.changeset/cuddly-eggs-kick.md (+5 -0)
📝 docs/content/docs/plugins/magic-link.mdx (+51 -0)
📝 packages/better-auth/src/api/to-auth-endpoints.test.ts (+57 -0)
📝 packages/better-auth/src/api/to-auth-endpoints.ts (+1 -1)
📝 packages/better-auth/src/plugins/magic-link/index.ts (+93 -34)
📝 packages/better-auth/src/plugins/magic-link/magic-link.test.ts (+266 -10)

📄 Description

Context

  • this PR is the follow-up created from the feedback on #8572
  • instead of returning the token from the existing HTTP/client sign-in flow, this version adds a separate server-only auth.api.generateMagicLink() API
  • a follow-up fix restores declared callback route paths in auth hooks so existing /callback/:id matchers keep working

Summary

  • add a separate server-only auth.api.generateMagicLink() that returns { status, url, token }
  • keep authClient.signIn.magicLink() and auth.api.signInMagicLink() status-only and still call sendMagicLink
  • share the issuance logic between the server-only and HTTP flows
  • preserve declared endpoint paths like /callback/:id while still giving pathless server-only endpoints a string hook path
  • document the new server helper and add regression coverage for both server parity and routed hook paths

Validation

  • pnpm exec vitest run packages/better-auth/src/plugins/magic-link/magic-link.test.ts
  • pnpm exec vitest run packages/better-auth/src/api/to-auth-endpoints.test.ts
  • pnpm exec vitest run packages/better-auth/src/social.test.ts
  • pnpm exec vitest run packages/better-auth/src/plugins/oauth-proxy/oauth-proxy.test.ts (callback/state regressions pass locally; the Postgres-backed UUID case requires the repo Docker setup)
  • pnpm exec vitest run packages/better-auth/src/api/routes/account.test.ts
  • pnpm exec vitest run packages/better-auth/src/oauth2/link-account.test.ts

🔄 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/8586 **Author:** [@mrgrauel](https://github.com/mrgrauel) **Created:** 3/13/2026 **Status:** 🔄 Open **Base:** `next` ← **Head:** `feat/expose-magic-link-token` --- ### 📝 Commits (10+) - [`3be60af`](https://github.com/better-auth/better-auth/commit/3be60afa97517e3446c4a2c6b8e6bf7956914aa4) feat(magic-link): add server-only generateMagicLink API - [`4e34060`](https://github.com/better-auth/better-auth/commit/4e34060b20932c01a95501a5384d43895098da41) fix(magic-link): require headers for generateMagicLink - [`a4a196f`](https://github.com/better-auth/better-auth/commit/a4a196f02a51f422439331a7490e91ddc5a04633) test(magic-link): document server parity for generateMagicLink - [`d5fd7a1`](https://github.com/better-auth/better-auth/commit/d5fd7a171984d92875c61bd9cbfc65fe0d772031) fix(api): preserve declared auth endpoint paths - [`d20f92b`](https://github.com/better-auth/better-auth/commit/d20f92bdc9d4aed9482b0e1dc4383d3afd302247) docs(magic-link): use APIMethod for generateMagicLink - [`8d82ca8`](https://github.com/better-auth/better-auth/commit/8d82ca880268fcf2c267f69a379f049e4a427a1b) refactor(magic-link): clean up type exports in magic link plugin - [`c931983`](https://github.com/better-auth/better-auth/commit/c931983471b0c8aea64f94e7657b94146ea1de4b) test(api): add test for fallback path in pathless endpoints - [`c69cfb4`](https://github.com/better-auth/better-auth/commit/c69cfb4625186a73be0cf96d8a607ee7f58a607f) docs(magic-link): clarify response structure for signInMagicLink and related endpoints - [`09d4de6`](https://github.com/better-auth/better-auth/commit/09d4de6230d7820460a2f2276b01e769693a4e13) Merge branch 'main' into feat/expose-magic-link-token - [`7c9ac86`](https://github.com/better-auth/better-auth/commit/7c9ac86f9a58a4e916f8e46dd12d17318cd69a98) docs(magic-link): update formatting in magic link documentation ### 📊 Changes **6 files changed** (+473 additions, -45 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/cuddly-eggs-kick.md` (+5 -0) 📝 `docs/content/docs/plugins/magic-link.mdx` (+51 -0) 📝 `packages/better-auth/src/api/to-auth-endpoints.test.ts` (+57 -0) 📝 `packages/better-auth/src/api/to-auth-endpoints.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/magic-link/index.ts` (+93 -34) 📝 `packages/better-auth/src/plugins/magic-link/magic-link.test.ts` (+266 -10) </details> ### 📄 Description ## Context - this PR is the follow-up created from the feedback on #8572 - instead of returning the token from the existing HTTP/client sign-in flow, this version adds a separate server-only `auth.api.generateMagicLink()` API - a follow-up fix restores declared callback route paths in auth hooks so existing `/callback/:id` matchers keep working ## Summary - add a separate server-only `auth.api.generateMagicLink()` that returns `{ status, url, token }` - keep `authClient.signIn.magicLink()` and `auth.api.signInMagicLink()` status-only and still call `sendMagicLink` - share the issuance logic between the server-only and HTTP flows - preserve declared endpoint paths like `/callback/:id` while still giving pathless server-only endpoints a string hook path - document the new server helper and add regression coverage for both server parity and routed hook paths ## Validation - `pnpm exec vitest run packages/better-auth/src/plugins/magic-link/magic-link.test.ts` - `pnpm exec vitest run packages/better-auth/src/api/to-auth-endpoints.test.ts` - `pnpm exec vitest run packages/better-auth/src/social.test.ts` - `pnpm exec vitest run packages/better-auth/src/plugins/oauth-proxy/oauth-proxy.test.ts` (callback/state regressions pass locally; the Postgres-backed UUID case requires the repo Docker setup) - `pnpm exec vitest run packages/better-auth/src/api/routes/account.test.ts` - `pnpm exec vitest run packages/better-auth/src/oauth2/link-account.test.ts` --- <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-04-15 22:40:13 -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#24981