Skip to main content

AI Prompt

Using AI to integrate Auth0? Add this prompt to Cursor, Windsurf, Copilot, Claude Code or your favourite AI-powered IDE to speed up development.
Prerequisites: Before you begin, ensure you have the following installed:Angular Version Compatibility: This quickstart works with Angular 18.x and newer using the Angular CLI. For older versions of Angular, use the Auth0 Angular SDK v2.

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 can choose to do this automatically by running a CLI command or do it manually via the Dashboard:
Run the following shell command on your project’s root directory to create an Auth0 app and generate an environment file:
4

Configure the Auth0 module

The CLI script has already created your environment file. Now configure the Auth0 module in your app:
src/main.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.
5

Create Login, Logout and Profile Components

Create the component files manually for better control
Add the following code to each component:Now update the main App Component and add styling:
Replace the contents of src/app/app.component.ts:
src/app/app.ts
6

Run your app

CheckpointYou should now have a fully functional Auth0 login page running on your localhost

Advanced Usage

If you prefer using NgModules instead of standalone components, here’s how to configure the SDK:
src/app/app.module.ts
Use the modern functional guard to protect routes that require authentication:
src/app/app.routes.ts
Then configure routing in your main.ts:
src/main.ts
Configure the HTTP interceptor to automatically attach tokens to API calls:
src/main.ts