File: creating-a-database-adapter.md | Updated: 11/15/2025
š NextAuth.js is now part of Better Auth !
Version: v4
On this page
Using a custom adapter you can connect to any database back-end or even several different databases. Official adapters created and maintained by our community can be found in the adapters packages. Feel free to add a custom adapter from your project to the repository, or even become a maintainer of a certain adapter. Custom adapters can still be created and used in a project without being added to the repository.
How to create an adapterā
For more information about creating an adapter, see this guide .
See the code below for practical example.
/** @return { import("next-auth/adapters").Adapter } */export default function MyAdapter(client, options = {}) { return { async createUser(user) { return }, async getUser(id) { return }, async getUserByEmail(email) { return }, async getUserByAccount({ providerAccountId, provider }) { return }, async updateUser(user) { return }, async deleteUser(userId) { return }, async linkAccount(account) { return }, async unlinkAccount({ providerAccountId, provider }) { return }, async createSession({ sessionToken, userId, expires }) { return }, async getSessionAndUser(sessionToken) { return }, async updateSession({ sessionToken }) { return }, async deleteSession(sessionToken) { return }, async createVerificationToken({ identifier, expires, token }) { return }, async useVerificationToken({ identifier, token }) { return }, }}
These methods are required for all sign in flows:
createUsergetUsergetUserByEmailgetUserByAccountlinkAccountcreateSessiongetSessionAndUserupdateSessiondeleteSessionupdateUserThese methods are required to support email / passwordless sign in:
createVerificationTokenuseVerificationTokenThese methods will be required in a future release, but are not yet invoked:
deleteUser
unlinkAccount