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

Auth.js · Const

Sendgrid

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.

How it works

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.

Syntax

Sendgrid(options)

Parameters

NameTypeDescription
apiKeystringSendgrid API key; when AUTH_SENDGRID_KEY is set, Auth.js can infer it automatically.
fromstringEmail address used as the sender; its domain must be added to Sendgrid.

Returns

A configured Auth.js Sendgrid email provider usable in the providers array.

Key points

  • Sendgrid provides passwordless sign-in by emailing a magic link containing a verification token.
  • Unless configured otherwise, the emailed verification token expires after 24 hours.
  • Redeeming the link within its validity period creates the account when needed and signs the user in.
  • Sendgrid supports both JWT-based and database-based session management.
  • After setup, the built-in sign-in endpoint starts the email flow when given an email address.
  • Store the Sendgrid API key in AUTH_SENDGRID_KEY for the provider's automatic environment-variable discovery.

Common mistakes

  • Email sign-in requires a configured database adapter; a JWT session alone does not remove this requirement.
  • The sender domain must first be added to Sendgrid, and the from address must use that domain.
  • Only the conventional AUTH_SENDGRID_KEY variable is inferred automatically; a differently named variable must be passed explicitly.

Example: Configure Sendgrid

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.

When to use it

Email magic-link sign-in

Passwordless authentication

Send verification messages through Sendgrid

Transactional email delivery

Use JWT or database-managed sessions

Flexible session handling

Interview questions

QHow does the Sendgrid provider authenticate a user?

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.

QWhat storage configuration is required?

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.

QHow is the Sendgrid API key configured?

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 provider
  • Verification Token
  • database adapter
  • AUTH_SENDGRID_KEY
  • signIn

Source: Sendgrid. Checked 2026-10-15.