Let returning users authenticate without entering a password.
Passwordless login
Better Auth · Module
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.
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.
authClient.signIn.magicLink({ email, name?, callbackURL?, newUserCallbackURL?, errorCallbackURL?, metadata? })| Name | Type | Description |
|---|---|---|
email | string (required) | Email address to send the magic link. |
name | string | User display name; used only for first-time registration. |
callbackURL | string | URL to redirect after magic-link verification. |
newUserCallbackURL | string | URL to redirect after new-user signup. |
errorCallbackURL | string | URL to redirect when verification fails. |
metadata | object | Additional metadata forwarded to sendMagicLink. |
The client call returns an object containing data and error; successful link verification authenticates the user and redirects to the configured callback.
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.
Passwordless login
First-time onboarding
Custom email delivery
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.
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.
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.
magicLinkClientsendMagicLinkauth.api.signInMagicLinkcallbackURLnewUserCallbackURLerrorCallbackURL