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

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

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

State: open
Merged: No


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
**Original Pull Request:** https://github.com/better-auth/better-auth/pull/8586 **State:** open **Merged:** No --- ## 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`
GiteaMirror added the pull-request label 2026-04-13 10:29:40 -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#16327