Module: adapters
This module contains functions and types that a database adapter can use to be compatible with Auth.js.
A database adapter provides a common interface for Auth.js so that it can work with any database/ORM adapter without concerning itself with the implementation details of the database/ORM.
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 (but will be logged out of the app). See this discussion for more information.
Installation​
- npm
- yarn
- pnpm
npm install @auth/core
yarn add @auth/core
pnpm add @auth/core
You can then import this submodule from @auth/core/adapters
.
Usage​
Built-in adapters already implement this interfac, so you likely won't need to implement it yourself. If you do, you can use the following example as a starting point.
import { type Adapter } from "@auth/core/adapters"
export function MyAdapter(config: {}): Adapter {
// implement the adapter methods
}
import { MyAdapter } from "./your-adapter"
const response = Auth({
adapter: MyAdapter({ /* ...adapter config */ }),
// ... auth config
})
Although @auth/core
is framework/runtime agnostic, an adapter might rely on a client/ORM package,
that is not yet compatible with your runtime
(E.g. it might rely on Node.js-specific APIs) when you are trying to use it elsewhere.
Related issues should be reported to the corresponding package maintainers.
Testing​
If you are writing your own adapter, there is a test suite available to ensure that your adapter is compatible with Auth.js.