Passwordless authentication
Let users sign in without remembering a password by emailing a one-time verification link.
Auth.js · Const
Nodemailer provides Auth.js email magic-link sign-in through an SMTP server. It sends verification-token links that sign users in or create their accounts, with a database required for token storage.
Nodemailer adds email-based magic-link authentication to Auth.js. Auth.js sends a verification token through an SMTP server; users follow the resulting link to sign in or create an account, while a database stores the verification token.
Nodemailer(config: NodemailerUserConfig): NodemailerConfig| Name | Type | Description |
|---|---|---|
server | string | NodemailerOptions | SMTP connection string or Nodemailer configuration object used to connect to the mail server. |
from | string | Email address used as the sender of verification messages. |
A configured Auth.js Nodemailer provider configuration.
import NextAuth from "next-auth"
import Nodemailer from "next-auth/providers/nodemailer"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [
Nodemailer({
server: process.env.EMAIL_SERVER,
from: process.env.EMAIL_FROM,
}),
],
})Configure Nodemailer with an SMTP connection string and sender address, then include it in Auth.js providers.
Let users sign in without remembering a password by emailing a one-time verification link.
Offer email sign-in alongside OAuth providers as a recovery path when an OAuth account is unavailable.
Use a conventional SMTP service while retaining Auth.js email-provider integration.
Nodemailer sends magic links containing verification tokens by email. The token is valid for 24 hours by default, and following the link signs in an existing user or creates a new account.
Follow-up: What infrastructure is mandatory? A database adapter must store the email verification token, even when using JWT-managed sessions.
The provider accepts either an SMTP connection string or a Nodemailer configuration object for the server connection. The configuration also supplies the sender address through from.
Follow-up: When should another provider be preferred? For HTTP-based email services, Auth.js recommends providers such as Resend or Sendgrid.
Nodemailer is not installed by Auth.js, so the package must be added separately before configuring the provider. An SMTP account is also required.
Follow-up: What must be configured beyond the package? A database adapter is needed to persist email verification tokens.
Email ProviderEmailConfigNodemailerConfigNodemailerUserConfigsendVerificationRequestVerification Tokendatabase adapter