New Project
Get started with a Next.js app with user login using Auth0
This sample demonstrates the integration of Auth0 Next.js SDK into a Next.js application created using create-next-app. The sample is a companion to the Auth0 Next.js SDK Quickstart.
This sample demonstrates the following use cases:
Use npm to install the project dependencies:
npm install
For the External API page to work, you will need to create an API using the management dashboard. This will give you an API Identifier that you can use in the AUTH0_AUDIENCE environment variable below. Then you will need to add a permission named read:shows to your API. To get your app to ask for that permission, include it in the value of the AUTH0_SCOPE environment variable.
If you do not wish to use an API or observe the API call working, you should not specify the AUTH0_AUDIENCE and AUTH0_SCOPE values in the next steps.
The project needs to be configured with your Auth0 Domain, Client ID and Client Secret for the authentication flow to work.
To do this, first copy .env.local.example into a new file in the same folder called .env.local, and replace the values with your own Auth0 application credentials (see more info about loading environmental variables in Next.js):
# A long secret value used to encrypt the session cookieAUTH0_SECRET='LONG_RANDOM_VALUE'# The base url of your applicationAPP_BASE_URL='http://localhost:3000'# Your Auth0 tenant domainAUTH0_DOMAIN='YOUR_AUTH0_DOMAIN.auth0.com'# Your Auth0 application's Client IDAUTH0_CLIENT_ID='YOUR_AUTH0_CLIENT_ID'# Your Auth0 application's Client SecretAUTH0_CLIENT_SECRET='YOUR_AUTH0_CLIENT_SECRET'# Your Auth0 API's Identifier# OMIT if you do not want to use the API part of the sampleAUTH0_AUDIENCE='YOUR_AUTH0_API_IDENTIFIER'# The permissions your app is asking for# OMIT if you do not want to use the API part of the sampleAUTH0_SCOPE='openid profile email read:shows'
Note: Make sure you replace AUTH0_SECRET with your own secret (you can generate a suitable string using openssl rand -hex 32 on the command line).
This compiles and serves the Next.js app and starts the API server on port 3001.
npm run dev
npm run build
To build and run the Docker image, run exec.sh, or exec.ps1 on Windows.
npm run test
npm run test:integration
Auth0 helps you to:
Easily deploy to the template to Vercel with the button below.
When using custom domains for your Vercel deployment, you will need to add them to the Allowed Callback URLs. More details here.
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
This project is licensed under the MIT license. See the LICENSE file for more info.
