NextAuth.js is a complete open source authentication solution for Next.js applications.
This is an example application which shows how next-auth
can be used with Azure AD to implement user authentication.
You can find more about the Azure AD provider for Next Auth here
NextAuth.js is an easy to implement, full-stack (client/server) open source authentication library designed for Next.js and Serverless.
Go to next-auth.js.org for more information and documentation.
NextAuth.js is not officially associated with Vercel or Next.js.
git clone https://github.com/425Show/next-auth-aad.git
cd next-auth-aad
npm install
Open the app-registrations.ipynb
and run through the Notebook to set up your Azure AD App registration. The Next.js app will
use this App Registration to authenticate.
Note: You'll need to install the .NET Interactive Notebook extension in VS Code to run this Notebook
Create an .env.local
file and add the following information. This information can be found on your Notebook from step #2
NEXTAUTH_URL=http://localhost:3000
AZURE_CLIENT_ID=<your Azure AD Client ID>
AZURE_TENANT_ID=<your Azure AD Tenant ID>
To run your site locally, use:
npm run dev
To run it it production mode, use:
npm build
npm start
You must set the NEXTAUTH_URL
environment variable with the URL of your site, before deploying to production.
e.g. in your .env.local
file - NEXTAUTH_URL=https://example.com
To do this with Vercel, you can use the Vercel project dashboard or their cli via the vc env
command:
vc env add NEXTAUTH_URL production
Do not forget to set the environment variables for the Client ID and Tenant ID values for all your configured authentication providers in your hosting providers dashboard, i.e. with Vercel as described above.
MIT