[GH-ISSUE #1292] Expose token generation method for magic link #8680

Closed
opened 2026-04-13 03:50:31 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @vixeven on GitHub (Jan 28, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1292

Is this suited for github?

  • Yes, this is suited for github

Currently, magic link authentication requires users to click on a link in their email, which can be inconvenient when using different devices or when email apps are not configured.

Users need a way to verify their email using a short code instead of clicking a link, similar to Notion's implementation where users can manually enter a code in the application.

Describe the solution you'd like

Expose the token generation method in the magic link plugin options to allow customizing the verification token format. This would enable developers to:

  • Generate shorter, numeric codes (e.g., 6-8 digits) instead of long strings
  • Keep the same security model but with a more user-friendly verification flow
  • Support both link-based and code-based verification methods

Describe alternatives you've considered

While Email OTP exists as a separate plugin, it doesn't support the key feature of magic links: automatic user registration for new users.

Magic links seems to uniquely handle both authentication AND registration in one flow, but currently force users to click links.

Additional context

  • The current generateRandomString() method could be made configurable through plugin options
  • Example implementation could look like:
magicLink({
  tokenGenerator: {
    type: 'numeric', // 'string', 'alphanumeric', ...
    length: 6,
    // other options like charset
  },

  // or alternatively
  tokenGenerator: () => generateNumericCode(6), // Custom 6-digit code generator
  
  sendMagicLink: async ({ email, token, url }) => {
    // token would be a 6-digit code instead of long string
  }
})
  • This would maintain backwards compatibility while adding more flexibility for different authentication UX patterns
Originally created by @vixeven on GitHub (Jan 28, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1292 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Currently, magic link authentication requires users to click on a link in their email, which can be inconvenient when using different devices or when email apps are not configured. Users need a way to verify their email using a short code instead of clicking a link, similar to Notion's implementation where users can manually enter a code in the application. ### Describe the solution you'd like Expose the token generation method in the magic link plugin options to allow customizing the verification token format. This would enable developers to: - Generate shorter, numeric codes (e.g., 6-8 digits) instead of long strings - Keep the same security model but with a more user-friendly verification flow - Support both link-based and code-based verification methods ### Describe alternatives you've considered While Email OTP exists as a separate plugin, it doesn't support the key feature of magic links: automatic user registration for new users. Magic links seems to uniquely handle both authentication AND registration in one flow, but currently force users to click links. ### Additional context - The current `generateRandomString()` method could be made configurable through plugin options - Example implementation could look like: ```typescript magicLink({ tokenGenerator: { type: 'numeric', // 'string', 'alphanumeric', ... length: 6, // other options like charset }, // or alternatively tokenGenerator: () => generateNumericCode(6), // Custom 6-digit code generator sendMagicLink: async ({ email, token, url }) => { // token would be a 6-digit code instead of long string } }) ``` - This would maintain backwards compatibility while adding more flexibility for different authentication UX patterns
GiteaMirror added the locked label 2026-04-13 03:50:31 -05:00
Author
Owner

@vixeven commented on GitHub (Jan 29, 2025):

From Email OTP documentation:

You can sign in the user using the signIn.emailOTP() method.
If the user is not registered, they'll be automatically registered.

This request is not valid.

<!-- gh-comment-id:2620871422 --> @vixeven commented on GitHub (Jan 29, 2025): From [`Email OTP`](https://www.better-auth.com/docs/plugins/email-otp#signin-with-otp) documentation: > You can sign in the user using the signIn.emailOTP() method. > If the user is not registered, they'll be **automatically registered**. This request is not valid.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8680