Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Better Auth · Module

signIn.magicLink

signIn.magicLink starts passwordless authentication by requesting a magic link for an email address. After the recipient follows the link, Better Auth authenticates them and redirects according to the request options.

How it works

The client method accepts an email and optional redirect and metadata settings, then asks Better Auth to send a one-time link. Following the generated link authenticates the user and redirects according to the selected callback URL.

Syntax

authClient.signIn.magicLink({ email, name?, callbackURL?, newUserCallbackURL?, errorCallbackURL?, metadata? })

Parameters

NameTypeDescription
emailstring (required)Email address to send the magic link.
namestringUser display name; used only for first-time registration.
callbackURLstringURL to redirect after magic-link verification.
newUserCallbackURLstringURL to redirect after new-user signup.
errorCallbackURLstringURL to redirect when verification fails.
metadataobjectAdditional metadata forwarded to sendMagicLink.

Returns

The client call returns an object containing data and error; successful link verification authenticates the user and redirects to the configured callback.

Key points

  • Invoke authClient.signIn.magicLink with the user’s email; email is the required request value.
  • Better Auth delegates delivery to the configured sendMagicLink callback.
  • Use callbackURL to choose where an existing user lands after successful verification.
  • The optional name value is applied only when the magic-link flow registers a user for the first time.
  • metadata lets application-specific values travel to the delivery callback.
  • Deliver the generated URL; clicking it completes authentication for the recipient.

Common mistakes

  • Provide errorCallbackURL when verification failures should use a dedicated destination; otherwise failures are sent to callbackURL with an error query parameter.
  • Configure the server-side sendMagicLink callback so the generated link is actually delivered to the user.

Example: Request a magic link

import { createAuthClient } from "better-auth/client";
import { magicLinkClient } from "better-auth/client/plugins";

const authClient = createAuthClient({
  plugins: [magicLinkClient()]
});

const { data, error } = await authClient.signIn.magicLink({
  email: "user@example.com",
  callbackURL: "/dashboard",
  newUserCallbackURL: "/welcome",
  errorCallbackURL: "/error"
});

if (error) console.error(error);
else console.log(data);

Loads the magic-link client plugin and requests a link for the supplied email, with separate destinations for verification, new-user signup, and errors.

When to use it

Let returning users authenticate without entering a password.

Passwordless login

Send new registrants to a dedicated welcome destination.

First-time onboarding

Forward metadata and the generated URL to application-controlled delivery logic.

Custom email delivery

Interview questions

QHow do you start magic-link sign-in?

Call authClient.signIn.magicLink with an object containing the required email field. The method requests that Better Auth send the authentication link.

Follow-up: What happens after the user clicks it? The link authenticates the user and redirects to the callbackURL supplied in the request.

QHow do redirect options differ?

callbackURL controls the destination after verification. newUserCallbackURL provides a separate destination when the link creates a new account.

Follow-up: How should verification failures be routed? Set errorCallbackURL; otherwise the callbackURL receives an error query parameter.

QWhat reaches sendMagicLink?

The request can include metadata, which is forwarded to the sendMagicLink callback. The callback receives the email, generated URL, token, and metadata, allowing custom delivery behavior.

Follow-up: How can a custom URL be sent? Use the token supplied to sendMagicLink to construct and deliver a custom link.

  • magicLinkClient
  • sendMagicLink
  • auth.api.signInMagicLink
  • callbackURL
  • newUserCallbackURL
  • errorCallbackURL

Source: Magic link - Better Auth. Checked 2026-10-15.