Email magic-link sign-in
Passwordless authentication
Auth.js · Const
Sendgrid is an Auth.js email provider for passwordless sign-in. It sends verification links through Sendgrid and requires a database adapter to store verification tokens.
Sendgrid is an email provider for Auth.js passwordless authentication. It emails a verification link, while Auth.js stores the verification token through a database adapter and signs the user in when the link is redeemed.
Sendgrid(options)| Name | Type | Description |
|---|---|---|
apiKey | string | Sendgrid API key; when AUTH_SENDGRID_KEY is set, Auth.js can infer it automatically. |
from | string | Email address used as the sender; its domain must be added to Sendgrid. |
A configured Auth.js Sendgrid email provider usable in the providers array.
from address must use that domain.import NextAuth from "next-auth"
import Sendgrid from "next-auth/providers/sendgrid"
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter,
providers: [
Sendgrid({
apiKey: process.env.AUTH_SENDGRID_KEY,
from: "no-reply@company.com",
}),
],
})Configure the Sendgrid provider with a database adapter, an API key, and a sender address from a verified domain.
Passwordless authentication
Transactional email delivery
Flexible session handling
Sendgrid implements passwordless email authentication by sending a link containing a verification token. The token is stored through the configured database adapter and, when used, Auth.js creates or signs in the account.
Follow-up: Why is the adapter mandatory? The verification token must be persisted so Auth.js can validate the link during the later request.
The provider can use JWT-managed or database-managed sessions, but email sign-in still needs a database adapter. The adapter stores the email verification token used during the sign-in flow.
Follow-up: Can a JWT session replace the adapter? No; the session strategy and token persistence solve different parts of the flow.
Auth.js automatically reads the API key from AUTH_SENDGRID_KEY. If the key uses another environment-variable name, pass that value as the provider's apiKey option.
Follow-up: What other provider setting must be configured for delivery? Set from to an address whose domain has been added to the Sendgrid account.
Email providerVerification Tokendatabase adapterAUTH_SENDGRID_KEYsignIn