Leave Localhost logoLeave LocalhostDocs
Emails

Magic Link Emails

The magic link email is sent when a user signs in with the passwordless magic link flow.

The magic link email is sent when a user signs in with the passwordless magic link flow.

Template

File: packages/backend/convex/email/templates/magicLinkEmail.tsx

The email contains:

  • A "Sign in to {APP_NAME}" CTA button with the magic link URL
  • A fallback text link for email clients that don't support buttons
  • A notice that the email can be ignored if not requested

How It's Triggered

Better Auth's magicLink plugin calls sendMagicLink during the magic link flow. This callback is configured in auth.ts:

magicLink({
  sendMagicLink: async ({ email, url }) => {
    const html = await renderMagicLinkEmail({ appName, url });
    const text = renderMagicLinkText({ appName, url });
    await sendEmail(requireRunMutationCtx(ctx), {
      to: email,
      subject: "Your sign-in link",
      html,
      text,
      from: env.RESEND_AUTH_FROM_EMAIL,
    });
  },
}),

Exports

FunctionReturns
MagicLinkEmail({ appName, url })React component
renderMagicLinkEmail({ appName, url })HTML string (via @react-email/render)
renderMagicLinkText({ appName, url })Plain text fallback

Customization

To customize the magic link email:

  1. Edit magicLinkEmail.tsx
  2. Update the preview text, button label, and body copy
  3. Keep the product name parameterized with appName
  4. Adjust the inline styles for your brand

Next Reads

On this page