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
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β
Name | Type |
---|---|
session | Object |
session.expires | Date |
session.sessionToken | string |
session.userId | string |
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β
Name | Type |
---|---|
sessionToken | string |
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β
Name | Type |
---|---|
userId | string |
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β
Name | Type |
---|---|
providerAccountId | Pick <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β
Name | Type |
---|---|
providerAccountId | Pick <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β
Name | Type |
---|---|
params | Object |
params.identifier | string |
params.token | string |
Returnsβ
Awaitable
<null
| VerificationToken
>