Module: adapters
The @auth/core/adapters
module contains useful helpers that a database adapter
can incorporate in order to be compatible with Auth.js.
You can think of an adapter as a way to normalize database implementation details to a common interface
that Auth.js can use to interact with the database.
Auth.js supports 2 session strtategies to persist the login state of a user.
The default is to use a cookie + JWT
based session store (strategy: "jwt"
),
but you can also use a database adapter to store the session in a database.
Auth.js currently does not implement federated logout. So even if the session is deleted from the database, the user will still be logged in to the provider. See this discussion for more information.
Installation​
- npm
- yarn
- pnpm
npm install @auth/core
yarn add @auth/core
pnpm add @auth/core
Usage​
Built-in adapters already implement this interface, so you likely won't need to implement it yourself. If you do, you can use the following example as a starting point.
// src/your-adapter.ts
import { type Adapter } from "@auth/core/adapters"
export function MyAdapter(options: any): Adapter {
// implement the adapter methods
}
// src/index.ts
import { MyAdapter } from "./your-adapter"
const response = Auth({
adapter: MyAdapter({ ...adapter options }),
... auth options
})