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

Auth.js · Const

XataAdapter

XataAdapter connects Auth.js to Xata for persisting users, sessions, and other authentication data. Configure it with a generated XataClient instance.

How it works

XataAdapter connects Auth.js to a Xata database. Give it a generated XataClient, then register the returned adapter in the Auth.js configuration so Auth.js can persist authentication data such as users and sessions.

Syntax

XataAdapter(client)

Parameters

NameTypeDescription
clientXataClientGenerated Xata client used to access the Xata database.

Returns

An Auth.js database adapter configured to use the supplied Xata client.

Key points

  • XataAdapter provides database persistence for Auth.js users, sessions, and additional authentication records.
  • Install the adapter from the @auth/xata-adapter package before configuring it.
  • Instantiate the generated XataClient that represents the Xata database connection.
  • Register the adapter by passing the Xata client to XataAdapter in Auth.js configuration.
  • Initialize the Xata project with the schema intended for Auth.js.

Common mistakes

  • Use the Xata CLI to create and configure the project rather than manually setting up the database.
  • The initialization command requires choosing a Xata workspace and database during setup.

Example: Configure Auth.js with Xata

import NextAuth from "next-auth"
import { XataAdapter } from "@auth/xata-adapter"
import { XataClient } from "../../../xata"

const client = new XataClient()

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

Create the generated Xata client and pass it to XataAdapter in the Auth.js configuration.

When to use it

Persist Auth.js data in Xata

Next.js application

Use Xata as the Auth.js database

Express application

Initialize the Auth.js-compatible schema with the Xata CLI

New Xata project

Interview questions

QWhat is XataAdapter used for?

XataAdapter is an Auth.js database adapter for Xata. It lets Auth.js use Xata to store users, sessions, and other authentication data.

Follow-up: What must be supplied to the adapter? A generated XataClient instance, passed as the adapter's argument.

QHow do you configure XataAdapter in Auth.js?

Install the @auth/xata-adapter package, create a XataClient, and configure adapter: XataAdapter(client) in the Auth.js options.

Follow-up: How would you initialize the Xata project? Use the Xata CLI with a schema file via xata init --schema=./path/to/your/schema.json.

QHow is the Xata database prepared?

The documented setup uses an Auth.js schema and initializes a Xata project with the Xata CLI. The CLI command accepts the path to that schema file.

Follow-up: Why is the schema needed? It provides the database structure that the Xata adapter expects for Auth.js data.

  • @auth/xata-adapter
  • XataClient
  • NextAuth
  • ExpressAuth
  • Xata CLI

Source: Xata Adapter - Auth.js. Checked 2026-10-15.