Example with live demo
You can find a live demo of the example project at next-auth-example.now.sh
How to use NextAuth.js
The examples below show how to add authentication with NextAuth.js to an existing Next.js project.
Add API route
To add NextAuth.js to a project, first create a file called
All requests to
/api/auth/* (signin, callback, signout, etc) will automatically be handed by NextAuth.js.
See the options documentation for how to configure providers, databases and other options.
Add React Hook
useSession() React Hook in the NextAuth.js client is the easiest way to check if someone is signed in.
That's all the code you need to add authentication to a project!
Check out the client documentation to see how you can improve the user experience and page performance by using the NextAuth.js client.