- Sign up and log in using a username and password or a Google account.
- Authenticate and authorize users using OAuth 2.0 and OpenID Connect.
Pick your tech stack
Prerequisites
Before getting started, make sure you have completed the following steps:1
Create an Auth0 Account
To continue with this quickstart, you need to have an Auth0 account.
2
Create an Auth0 Application
Go to your Auth0 Dashboard to create a new Auth0 Application.
- Navigate to Applications > Applications in the left sidebar.
- Click the Create Application button in the top right.
- In the pop-up select Regular Web Applications and click Create.
- Once the Application is created, switch to the Settings tab.
- Scroll down to the Application URIs section.
- Set Allowed Callback URLs as:
http://localhost:3000/auth/callback
- Set Allowed Logout URLs as:
http://localhost:3000
- Click Save in the bottom right to save your changes.
Create a Next.js app
Use a starter template or create a Next.js web application using Next.js version 15 or above.Recommended: Use this starter template from the Auth0 AI samples repository:Install dependencies
In the root directory of your project, install the Auth0 Next.js SDK:Add log in to your application
Secure your application using the Auth0 Next.js SDK.Create your environment file
In the root directory of your project, create a new file and name it.env.local
and add the following content:.env.local
AUTH0_DOMAIN
, AUTH0_CLIENT_ID
, and AUTH0_CLIENT_SECRET
by viewing the Auth0 Application that you created in the Auth0 Dashboard and navigating to the Basic Information section at the top of the Settings tab.
Copy each value to the matching setting.Next, run this command to generate a random 32 byte value and copy it to the AUTH0_SECRET
field.generate random 32 byte value
Create the Auth0 client
Create a new file in thesrc/lib
directory and name it auth0.ts
. Add the following code to create a new Auth0 client:src/lib/auth0.ts
Add the authentication middleware
The middleware intercepts incoming requests and applies Auth0’s authentication logic. Create a new file in thesrc
directory and name it middleware.ts
. Add the following code to the file:src/middleware.ts
Add Log in and Sign up buttons
Update thesrc/app/page.tsx
file with the following code to check if the user is signed in or not.
It will display the Sign up or Log in buttons without a user session. If a user session exists, the app displays a welcome message with the user’s name.src/app/page.tsx
Add user profile dropdown (optional)
If you are using the starter template, you can add a user profile dropdown to your application. Update thesrc/app/layout.tsx
file:src/app/layout.tsx
Run your application
Run this command to start your server:http://localhost:3000
in your browser.You will see:
View a complete example
Want to see how it all comes together? Explore or clone the fully implemented sample application here on GitHub.Next steps
- To set up first-party tool calling, complete the Call your APIs on user’s behalf quickstart.
- To set up third-party tool calling, complete the Call other’s APIs on user’s behalf quickstart.
- Learn more about User Authentication.