This quickstart demonstrates how to add Auth0 authentication to a Nuxt.js application. You’ll build a secure single-page app with login, logout, and user profile features using the Auth0 Nuxt SDK.
1
Create a new project
Create a new Nuxt project for this Quickstart
Report incorrect code
Copy
Ask AI
npx nuxi@latest init auth0-nuxt-app
Open the project
Report incorrect code
Copy
Ask AI
cd auth0-nuxt-app
2
Install the Auth0 Nuxt SDK
Report incorrect code
Copy
Ask AI
npm add @auth0/auth0-nuxt && npm install
3
Setup your Auth0 App
Next up, you need to create a new app on your Auth0 tenant and add the environment variables to your project.You can choose to do this automatically by running a CLI command or do it manually via the Dashboard:
CLI
Dashboard
Run the following shell command on your project’s root directory to create an Auth0 app and generate a .env file:
Click on Applications > Applications > Create Application
In the popup, enter a name for your app, select Regular Web Application as the app type and click Create
Switch to the Settings tab on the Application Details page
Replace the values in the .env file with the Domain, Client ID, and Client Secret values from the dashboard
Generate a session secret by running: openssl rand -hex 64 and use it for NUXT_AUTH0_SESSION_SECRET
Finally, on the Settings tab of your Application Details page, configure the following URLs:Allowed Callback URLs:
Report incorrect code
Copy
Ask AI
http://localhost:3000/auth/callback
Allowed Logout URLs:
Report incorrect code
Copy
Ask AI
http://localhost:3000
Allowed Web Origins:
Report incorrect code
Copy
Ask AI
http://localhost:3000
Allowed Callback URLs are a critical security measure to ensure users are safely returned to your application after authentication. Without a matching URL, the login process will fail, and users will be blocked by an Auth0 error page instead of accessing your app.
Allowed Logout URLs are essential for providing a seamless user experience upon signing out. Without a matching URL, users will not be redirected back to your application after logout and will instead be left on a generic Auth0 page.Allowed Web Origins is critical for silent authentication. Without it, users will be logged out when they refresh the page or return to your app later.