Passwordless login
Users authenticate without passwords by receiving a one-time sign-in link by email.
Auth.js · Const
Mailgun enables passwordless Auth.js sign-in by emailing magic links with verification tokens. It requires a database adapter for token storage and supports JWT or database-managed sessions.
Mailgun sends passwordless sign-in links containing verification tokens. Auth.js stores those tokens through a database adapter, and the token is valid for 24 hours by default; the provider can use either JWT or database sessions after the required database is configured.
Mailgun(config)| Name | Type | Description |
|---|---|---|
config | EmailUserConfig & { region: "US" | "EU" } | Email provider configuration plus the Mailgun server region, either US or EU. |
EmailConfig
import { Auth } from "@auth/core"
import Mailgun from "@auth/core/providers/mailgun"
const request = new Request("https://example.com")
const response = await Auth(request, {
adapter,
providers: [
Mailgun({
from: process.env.MAILGUN_DOMAIN!,
region: "EU",
}),
],
})This configures Auth.js with Mailgun email sign-in, using the Mailgun domain as the sender and the EU endpoint.
Users authenticate without passwords by receiving a one-time sign-in link by email.
An application needs email authentication alongside social login providers.
A deployment sends mail through Mailgun's European service.
Mailgun is an email provider that sends a magic link containing a verification token. When the recipient uses a valid link, Auth.js creates the account on first sign-in and signs the user in; the default token lifetime is 24 hours.
Follow-up: What persistence is required? A database adapter must store the email verification token, even if sessions are managed with JWTs.
The provider accepts an EmailUserConfig together with a region of either US or EU, and returns an EmailConfig. A typical configuration supplies the sender domain through from and optionally sets region: "EU".
Follow-up: How can the API-key configuration stay implicit? Name the environment variable AUTH_MAILGUN_KEY so the provider discovers it automatically.
The provider can be registered in the Auth.js providers array. The Mailgun API key can be stored in AUTH_MAILGUN_KEY; using that exact name lets the provider pick it up without passing the key manually.
Follow-up: What else must be configured before sign-in works? Add a database adapter, then start the flow at the application's /api/auth/signin endpoint.
EmailConfigEmailUserConfigVerification Tokendatabase adapterJSON Web TokenAUTH_MAILGUN_KEY