Skip to main content

Use AI to integrate Auth0

If you use an AI coding assistant like Claude Code, Cursor, or GitHub Copilot, you can add Auth0 authentication automatically in minutes using agent skills.Install:
Then ask your AI assistant:
Your AI assistant will automatically create your Auth0 application, fetch credentials, install @auth0/auth0-angular, create route guards and HTTP interceptors, and configure your environment. Full agent skills documentation →
Prerequisites: Before you begin, ensure you have the following installed:Verify installation: node --version && npm --versionAngular Version Compatibility: This quickstart works with Angular 19 through 21 using the Angular CLI. The @auth0/auth0-angular SDK supports Angular 13 and newer.

Get Started

This quickstart demonstrates how to add Auth0 authentication to an Angular application. You’ll build a secure single-page app with login and logout functionality using Angular’s dependency injection system and the Auth0 Angular SDK.
1

Create a new project

Create a new Angular project for this Quickstart
Open the project
2

Install the Auth0 Angular SDK

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 have three options to set up your Auth0 app: use the Quick Setup tool (recommended), run a CLI command, or configure manually via the Dashboard:
4

Configure the Auth0 module

With your environment file in place from the previous step, add provideAuth0 to the providers array in your app.config.ts:
src/app/app.config.ts
If you set up your Auth0 app manually via the dashboard, create src/environments/environment.ts with your domain and client ID from the dashboard.Angular 20+ projects also include provideBrowserGlobalErrorListeners() in this file — keep it in the array alongside provideAuth0. No changes to main.ts are needed.
5

Create Login, Logout and Profile Components

Use the Angular CLI to scaffold the component files:
Add the following code to each component:Now update the main App Component and add styling:
Replace the contents of your app component file (src/app/app.ts on Angular 20+, or src/app/app.component.ts on Angular 19):
src/app/app.ts
6

Run your app

If port 4200 is in use, run: ng serve --port 4201 and update your Auth0 app’s callback URLs to http://localhost:4201
CheckpointYou should now have a fully functional Auth0 login page running on your localhost

Advanced Usage

If you created your project with --standalone=false or prefer using NgModules instead of standalone components, here’s how to configure the SDK with Angular 20+ CLI-generated projects:
src/main.ts
src/app/app-module.ts
If you’re using Angular 19, your generated files are typically app.component.ts, app.module.ts, and app-routing.module.ts, and main.ts uses platformBrowserDynamic instead of platformBrowser.Angular 20+ generates app.ts, app-module.ts, and app-routing-module.ts (no dots in filenames), and main.ts uses platformBrowser as shown above.In all cases, NgModule projects bootstrap via bootstrapModule() rather than the bootstrapApplication() approach shown in the main quickstart.
Use the modern functional guard to protect routes that require authentication:
src/app/app.routes.ts
Then add provideAuth0 and the router to your app.config.ts (if you haven’t already from Step 4):
src/app/app.config.ts
Configure the HTTP interceptor to automatically attach tokens to API calls. Add provideHttpClient with the Auth0 interceptor and an audience to your app.config.ts:
src/app/app.config.ts