Database-backed authentication
Persist Auth.js users, accounts, sessions, and verification data through a Kysely database client.
Auth.js · Const
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.
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.
function KyselyAdapter(db): Adapter| Name | Type | Description |
|---|---|---|
db | Kysely<Database> | A configured Kysely database instance whose Database interface describes the schema. |
Adapter
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.
Persist Auth.js users, accounts, sessions, and verification data through a Kysely database client.
Use generated database typings while retaining Auth.js schema validation.
Connect Auth.js to a PostgreSQL, MySQL, or SQLite database through Kysely.
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.
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.
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.
KyselyAuthAdapterkysely-codegenCodegen