Persist Auth.js data in Xata
Next.js application
Auth.js · Const
XataAdapter connects Auth.js to Xata for persisting users, sessions, and other authentication data. Configure it with a generated XataClient instance.
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.
XataAdapter(client)| Name | Type | Description |
|---|---|---|
client | XataClient | Generated Xata client used to access the Xata database. |
An Auth.js database adapter configured to use the supplied Xata client.
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.
Next.js application
Express application
New Xata project
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.
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.
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-adapterXataClientNextAuthExpressAuthXata CLI