Skip to main content

Interface: Adapter

adapters.Adapter

An adapter is an object with function properties (methods) that read and write data from a data source. Think of these methods as a way to normalize the data layer to common interfaces that Auth.js can understand.

This is what makes Auth.js very flexible and allows it to be used with any data layer.

The adapter methods are used to perform the following operations:

  • Create/update/delete a user
  • Link/unlink an account to/from a user
  • Handle active sessions
  • Support passwordless authentication across multiple devices
note

If any of the methods are not implemented, but are called by Auth.js, an error will be shown to the user and the operation will fail.

Methods​

createSession​

β–Έ Optional createSession(session): Awaitable<AdapterSession>

Creates a session for the user and returns it.

Parameters​

NameType
sessionObject
session.expiresDate
session.sessionTokenstring
session.userIdstring

Returns​

Awaitable<AdapterSession>


deleteSession​

β–Έ Optional deleteSession(sessionToken): Promise<void> | Awaitable<undefined | null | AdapterSession>

Deletes a session from the database. It is preferred that this method also returns the session that is being deleted for logging purposes.

Parameters​

NameType
sessionTokenstring

Returns​

Promise<void> | Awaitable<undefined | null | AdapterSession>


deleteUser​

β–Έ Optional deleteUser(userId): Promise<void> | Awaitable<undefined | null | AdapterUser>

Todo

This method is currently not invoked yet.

Parameters​

NameType
userIdstring

Returns​

Promise<void> | Awaitable<undefined | null | AdapterUser>


getUserByAccount​

β–Έ Optional getUserByAccount(providerAccountId): Awaitable<null | AdapterUser>

Using the provider id and the id of the user for a specific account, get the user.

Parameters​

NameType
providerAccountIdPick<AdapterAccount, "provider" | "providerAccountId">

Returns​

Awaitable<null | AdapterUser>


unlinkAccount​

β–Έ Optional unlinkAccount(providerAccountId): Promise<void> | Awaitable<undefined | AdapterAccount>

Todo

This method is currently not invoked yet.

Parameters​

NameType
providerAccountIdPick<AdapterAccount, "provider" | "providerAccountId">

Returns​

Promise<void> | Awaitable<undefined | AdapterAccount>


useVerificationToken​

β–Έ Optional useVerificationToken(params): Awaitable<null | VerificationToken>

Return verification token from the database and delete it so it cannot be used again.

Parameters​

NameType
paramsObject
params.identifierstring
params.tokenstring

Returns​

Awaitable<null | VerificationToken>