Learn how Auth for GenAI enables AI agents to seamlessly authenticate users.
Create an Auth0 Account
Create an Auth0 Application
http://localhost:3000/auth/callback
http://localhost:3000
.env.local
and add the following content: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.src/lib
directory and name it auth0.ts
. Add the following code to create a new Auth0 client:src
directory and name it middleware.ts
. Add the following code to the file:src/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/layout.tsx
file:http://localhost:3000
in your browser.You will see: