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

Auth.js · Const

KyselyAdapter

KyselyAdapter connects Auth.js to a Kysely database and returns an Auth.js Adapter. Its typed wrapper validates that the database interface includes the fields Auth.js expects.

How it works

KyselyAdapter accepts a Kysely database instance and returns an Auth.js Adapter. It wraps the database integration so Auth.js can use Kysely for its authentication data while validating the database interface required by Auth.js.

Syntax

function KyselyAdapter(db): Adapter

Parameters

NameTypeDescription
dbKysely<Database>A configured Kysely database instance whose Database interface describes the schema.

Returns

Adapter

Key points

  • KyselyAdapter is Auth.js’s official integration for connecting authentication persistence to Kysely.
  • The function receives a database client and produces an Auth.js Adapter.
  • Generated Kysely types from kysely-codegen can be supplied as the second generic type argument.
  • With generated types, KyselyAuth checks for the required fields rather than replacing the generated database typing.
  • The documented first-party dialects are PostgreSQL, MySQL, and SQLite.

Common mistakes

  • Although a plain Kysely instance is accepted, using the documented wrapper helps verify that the database type contains the fields Auth.js needs.
  • Your Kysely database type must define an interface entry for every table.

Example: Use KyselyAdapter with Auth.js

import { KyselyAdapter } from "@auth/kysely-adapter"
import { db } from "./db"

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

Pass the Kysely database instance to the adapter, then configure the returned adapter in Auth.js.

When to use it

Database-backed authentication

Persist Auth.js users, accounts, sessions, and verification data through a Kysely database client.

Generated schema types

Use generated database typings while retaining Auth.js schema validation.

Supported SQL dialects

Connect Auth.js to a PostgreSQL, MySQL, or SQLite database through Kysely.

Interview questions

QWhat does KyselyAdapter do and how is it configured?

KyselyAdapter takes a Kysely database instance and returns an Auth.js Adapter. Configure it by assigning KyselyAdapter(db) to the Auth.js adapter option.

Follow-up: Why use KyselyAuth instead of an ordinary Kysely instance? KyselyAuth validates that the database interface includes the fields Auth.js requires.

QWhat are the parameter and return types?

The db parameter is typed as Kysely<Database>, and the function returns Adapter. The returned adapter connects Auth.js operations to the supplied Kysely database.

Follow-up: What must the Database interface contain? It needs an interface entry for each table used by the Kysely database schema.

QWhat setup is required before using the adapter?

Install both @auth/kysely-adapter and kysely, then import KyselyAdapter and pass the configured database client to it. The adapter can be used in an Auth.js configuration.

Follow-up: Which database engines are documented as supported by this adapter? PostgreSQL, MySQL, and SQLite are listed through Kysely's first-party dialect support.

  • KyselyAuth
  • Adapter
  • kysely-codegen
  • Codegen

Source: Auth.js | Kysely Adapter. Checked 2026-10-15.