Using a custom adapter you can connect to any database backend or even several different databases. Custom adapters created and maintained by our community can be found in the adapters repository. 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.
Creating a custom adapter can be considerable undertaking and will require some trial and error and some reverse engineering using the built-in adapters for reference.
From an implementation perspective, an adapter in NextAuth.js is a function which returns an async
getAdapter() method, which in turn returns a Promise with a list of functions used to handle operations such as creating user, linking a user and an OAuth account or handling reading and writing sessions.
It uses this approach to allow database connection logic to live in the
getAdapter() method. By calling the function just before an action needs to happen, it is possible to check database connection status and handle connecting / reconnecting to a database as required.
See the code below for practical example.
These methods are required for all sign in flows:
These methods are required to support email / passwordless sign in:
These methods will be required in a future release, but are not yet invoked: