NextAuth.js comes with its own type definitions, so you can safely use it in your TypeScript projects. Even if you don't use TypeScript, IDEs like VSCode will pick this up, to provide you with a better developer experience. While you are typing, you will get suggestions about what certain objects/functions look like, and sometimes also links to documentation, examples and other useful resources.
Check out the example repository showcasing how to use
next-auth on a Next.js application with TypeScript:
The types at DefinitelyTyped under the name of
@types/next-auth are now deprecated, and not maintained anymore.
If you're writing your own custom Adapter, you can take advantage of the types to make sure your implementation conforms to what's expected:
This will work in code editors with a strong TypeScript integration like VSCode or WebStorm. It might not work if you're using more lightweight editors like VIM or Atom.
next-auth comes with certain types/interfaces, that are shared across submodules. Good examples are
JWT. Ideally, you should only need to create these types at a single place, and TS should pick them up in every location where they are referenced. Luckily, this is exactly what Module Augmentation can do for us. Define your shared interfaces in a single location, and get type-safety across your application, when you use
next-auth (or one of its submodules).
Let's look at
To extend/augment this type, create a
types/next-auth.d.ts file in your project:
Although you can augment almost anything, here are some of the more common interfaces that you might want to override in the
Make sure that the
types folder is added to
typeRoots in your project's
JWT interface can be found in the
Contributions of any kind are always welcome, especially for TypeScript. Please keep in mind that we are a small team working on this project in our free time. We will try our best to give support, but if you think you have a solution for a problem, please open a PR!