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

Auth.js · Const

PostgresAdapter

PostgresAdapter is Auth.js’s official PostgreSQL adapter. Give it a PostgreSQL Pool to obtain an Adapter for the NextAuth configuration.

How it works

PostgresAdapter accepts a PostgreSQL connection pool and produces an Auth.js-compatible adapter. Supply the resulting adapter to NextAuth so Auth.js can use PostgreSQL for persisted authentication data.

Syntax

function default(client): Adapter

Parameters

NameTypeDescription
clientPoolPostgreSQL connection pool used by the adapter.

Returns

Adapter

Key points

  • PostgresAdapter is Auth.js's official adapter for PostgreSQL-backed authentication.
  • The exported default function receives a client and returns an Auth.js Adapter.
  • Pass the constructed adapter through the adapter property in the NextAuth configuration.
  • The npm setup requires next-auth, @auth/pg-adapter, and pg.

Common mistakes

  • For edge deployments using Neon-compatible PostgreSQL, use the serverless PostgreSQL package rather than the standard pg client.

Example: Configure the PostgreSQL adapter

import NextAuth from "next-auth"
import PostgresAdapter from "@auth/pg-adapter"
import { Pool } from "pg"

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
})

export const { handlers, auth, signIn, signOut } = NextAuth({
  adapter: PostgresAdapter(pool),
  providers: [],
})

Create a PostgreSQL connection pool and pass it to PostgresAdapter in the Auth.js configuration.

When to use it

PostgreSQL-backed authentication

Persist Auth.js users, accounts, and sessions in a PostgreSQL database.

Reuse a database pool

Connect a NextAuth configuration to an existing node-postgres pool.

Edge-compatible PostgreSQL

Run Auth.js with Neon-compatible PostgreSQL in an edge environment.

Interview questions

QWhat does PostgresAdapter do?

PostgresAdapter is the default export from @auth/pg-adapter. It takes a pg Pool and returns an Adapter that can be passed as the adapter option to NextAuth.

Follow-up: What must the caller provide? A PostgreSQL Pool configured for the target database; the adapter does not accept a database name or connection string directly in this signature.

QHow is PostgresAdapter configured in Auth.js?

Install @auth/pg-adapter together with pg, create a Pool, and invoke PostgresAdapter(pool). The returned value is then assigned to adapter in the Auth.js configuration.

Follow-up: How would an edge deployment differ? Use @neondatabase/serverless for Neon-compatible PostgreSQL instead of the conventional pg package.

QWhat are the parameter and return types?

The function parameter is named client and has type Pool. Its return type is Adapter, which is the interface Auth.js uses for database persistence.

Follow-up: Why is the return type significant? It means the adapter exposes the standard Auth.js adapter contract rather than a PostgreSQL-specific API.

  • Adapter
  • Pool
  • @auth/pg-adapter
  • @neondatabase/serverless

Source: auth/pg-adapter - Auth.js. Checked 2026-10-15.