FusionAuth QuickStart for Angular
On this page
This QuickStart adds login and a protected page to an Angular web app using a preconfigured, local version of FusionAuth in the following steps:
- Create a new Angular app.
- Customize the app with home and account pages.
- Add login to protect the account page.
- Give each user their own note on the account page.
Prerequisites#
This QuickStart requires:
If you use macOS or Windows, you need one of the following container management tools:
- Docker Desktop
- OrbStack (to use OrbStack for
docker composecommands after installation, rundocker context use orbstack) - Podman (in the commands below, replace
dockerwithpodman)
Install and Run FusionAuth#
To begin, clone the GitHub repository for this QuickStart to your local machine:
$ git clone https://github.com/FusionAuth/fusionauth-quickstart-javascript-angular-web
The repository contains:
backend_fusionauth, a preconfigured version of FusionAuthfrontend_steps, a runnable version of each development step of the Angular application
Navigate to fusionauth-quickstart-javascript-angular-web/backend_fusionauth:
$ cd fusionauth-quickstart-javascript-angular-web/backend_fusionauth
If you are not using Linux, then start your container runtime, such as Docker Desktop, OrbStack, or Podman before running Docker Compose.
To start a local instance of FusionAuth, run the following command:
$ docker compose up -d
During Docker Compose startup, the included kickstart/kickstart.json file uses the FusionAuth API to:
- Generate an API key
- Configure CORSA browser security mechanism that lets a web page request restricted resources from another domain when the server allows the request. (Settings -> System -> CORS )
- Create your app ("QuickStart App") with appropriate settings and redirect URIs (Applications -> Edit Application )
- Create an admin user (admin@example.com) with access to the FusionAuth Admin UI (Users )
- Create a user (richard@example.com) and register the user with your app
- Create a custom theme ("QuickStart Theme") using
backend_fusionauth/kickstart/css/styles.cssand apply it to your default tenantThe Tenant that FusionAuth creates during installation. You can't delete the Default Tenant, which hosts the FusionAuth Admin UI Application. (Customizations -> Themes )
Once Docker Compose initializes all containers, open a browser and navigate to the FusionAuth Admin UI at http://localhost:9011/admin. Use the following admin account credentials to log in:
- Username:
admin@example.com - Password:
password
After authenticating, you should see the FusionAuth Admin UI, which shows information about active users, logins, registrations, and more:

Create the Angular App#
Open a new terminal in the fusionauth-quickstart-javascript-angular-web directory to create the frontend app.
- Run the command below to create a new Angular app using a minimal template:
$ npx @angular/cli@22.2.6 new app --defaults --inline-template --inline-style --style=css --skip-git --skip-tests --ssr=false --ai-config=none - Run the app:
$ cd app $ npx @angular/cli@22.2.6 serve --host=0.0.0.0 --port=3000
You can now browse to the web app at http://localhost:3000 (which matches the allowed authentication URL defined in the FusionAuth Kickstart file earlier).
As you follow this guide, the app should hot-reload when you change the source files. But if the page doesn't refresh, press Ctrl C to stop the Angular server, then press Up and Enter to rerun the serve command.
Customize the Angular App#
Update the Main App Component#
Replace the contents of src/app/app.ts with the following code:
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
@Component({
imports: [RouterOutlet],
selector: 'app-root',
template: '<router-outlet />',
})
export class App {}
This deletes the placeholder welcome text on the homepage.
Configure the Routes#
Replace the contents of src/app/app.routes.ts with the following code:
import { Routes } from '@angular/router';
import { Account } from './account';
import { Home } from './home';
export const routes: Routes = [
{ path: '', component: Home },
{ path: 'account', component: Account },
{ path: '**', redirectTo: '' },
];
The homepage is displayed at /, and the account page at /account.
Create the Homepage#
Create src/app/home.ts with the following code:
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
@Component({
imports: [RouterLink],
selector: 'app-home',
template: `
<header class="titlebar">
<a class="button" routerLink="/account">Login</a>
</header>
<main class="centerContainer">
<div>Log in to request your information</div>
</main>
`,
})
export class Home {}
The Login link navigates to the account page. You'll replace this navigation with the FusionAuth login flow in the next section.
Create the Account Page#
Create src/app/account.ts with the following code:
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
@Component({
imports: [RouterLink],
selector: 'app-account',
template: `
<header class="titlebar">
<a class="button" routerLink="/">Logout</a>
</header>
<main class="centerContainer">
<p>Your note will display here</p>
</main>
`,
})
export class Account {}
The Logout link returns to the homepage. You'll replace this navigation with the FusionAuth logout flow in the next section.
Update the Stylesheet#
Replace the contents of src/styles.css with the following CSS:
.white {
color: white;
}
* {
color: #1e293b;
font-family: Inter, Arial, Helvetica, sans-serif;
font-size: 14px;
margin: 0;
padding: 0;
}
.centerContainer {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.titlebar {
background-color: #1e293b;
margin: 0 0 36px 0;
min-height: 100px;
color: #f8fafc;
display: flex;
justify-content: flex-end;
align-items: center;
}
.button {
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
font-family: inherit;
border-radius: 4px;
padding: 10px 16px;
margin: 16px;
height: 40px;
background-color: #f58320;
border: none;
color: white;
text-decoration: none;
transition: background 0.2s ease-in-out;
}
.button:hover {
background-color: #ea580c;
color: white;
transition: background 0.2s ease-in-out;
}
h2 {
font-size: 18px;
margin-bottom: 16px;
}
.note {
width: 400px;
height: 160px;
padding: 10px;
border: 1px solid #cbd5e1;
border-radius: 4px;
}
Add FusionAuth for Authentication#
In this section, you'll protect the account page by requiring users to log in.
Configure and Enable FusionAuth#
-
Open a new terminal in the
appdirectory and run the following command to install the FusionAuth Angular SDK:$ npm install @fusionauth/angular-sdk@~2.1.0 -
Open
src/app/app.config.tsand replace the file contents with the following code to:- configure the FusionAuth Angular SDK
- register
FusionAuthModulewith Angular's application providers
import { ApplicationConfig, importProvidersFrom, provideBrowserGlobalErrorListeners } from '@angular/core'; import { FusionAuthModule } from '@fusionauth/angular-sdk'; import type { FusionAuthConfig } from '@fusionauth/angular-sdk'; import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; const fusionAuthConfig: FusionAuthConfig = { redirectUri: 'http://localhost:3000', postLogoutRedirectUri: 'http://localhost:3000', shouldAutoRefresh: true, scope: 'openid email profile offline_access', clientId: 'e9fdb985-9173-4e01-9d73-ac2d60d1dc8e', serverUrl: 'http://localhost:9011', onRedirect: () => console.log('Login successful'), }; export const appConfig: ApplicationConfig = { providers: [ provideBrowserGlobalErrorListeners(), provideRouter(routes), importProvidersFrom(FusionAuthModule.forRoot(fusionAuthConfig)), ], };
This FusionAuth configuration specifies the following values:
redirectUri: URI to open after a successful login.postLogoutRedirectUri: URI to open after logout.shouldAutoRefresh: Set to automatically renew the access token.scope: OAuth 2.0 permissions for the access token.clientId: Id of the application in the FusionAuth instance.serverUrl: Base URL for the FusionAuth authorization server.onRedirect: Callback that executes when a redirect occurs.
Add Login and Logout to Homepage#
Open src/app/home.ts and replace the file contents with the following code to:
- use the FusionAuth Angular SDK to start login and logout
- redirect authenticated users to the account page
- display the authenticated user's email and logout button, or a login button when logged out
import { Component, effect, Inject, signal } from '@angular/core';
import { FusionAuthService } from '@fusionauth/angular-sdk';
import type { UserInfo } from '@fusionauth/angular-sdk';
import { Router } from '@angular/router';
@Component({
selector: 'app-home',
template: `
<header class="titlebar">
@if (fusionAuth.isLoggedInSignal()) {
<span class="white">{{ userInfo()?.email }}</span>
<button class="button" type="button" (click)="logout()">Logout</button>
} @else {
<button class="button" type="button" (click)="login()">Login</button>
}
</header>
<main class="centerContainer">
<div>Log in to request your information</div>
</main>
`,
})
export class Home {
protected readonly userInfo = signal<UserInfo | null>(null);
constructor(
protected readonly fusionAuth: FusionAuthService,
@Inject(Router) private readonly router: Router,
) {
effect(() => {
if (!this.fusionAuth.isLoggedInSignal()) return;
void this.loadUserInfo();
void this.router.navigateByUrl('/account');
});
}
protected login(): void {
this.fusionAuth.startLogin();
}
protected logout(): void {
this.fusionAuth.logout();
}
private async loadUserInfo(): Promise<void> {
try { this.userInfo.set(await this.fusionAuth.getUserInfo<UserInfo>()); }
catch (error) { console.error('Unable to fetch FusionAuth user info', error); }
}
}
Add Logout to Account Page#
Open src/app/account.ts and replace the file contents with the following code to:
- redirect logged-out users to the homepage
- retrieve and display the authenticated user's email
- log the user out with the Angular SDK's
logout()method
import { Component, Inject, signal } from '@angular/core';
import { FusionAuthService } from '@fusionauth/angular-sdk';
import type { UserInfo } from '@fusionauth/angular-sdk';
import { Router } from '@angular/router';
@Component({
selector: 'app-account',
template: `
@if (fusionAuth.isLoggedInSignal() && !isFetchingUserInfo()) {
<header class="titlebar">
<span class="white">{{ userInfo()?.email }}</span>
<button class="button" type="button" (click)="logout()">Logout</button>
</header>
<main class="centerContainer">
<p>Your note will display here</p>
</main>
}
`,
})
export class Account {
protected readonly isFetchingUserInfo = signal(false);
protected readonly userInfo = signal<UserInfo | null>(null);
constructor(
protected readonly fusionAuth: FusionAuthService,
@Inject(Router) private readonly router: Router,
) {
if (!this.fusionAuth.isLoggedIn()) {
void this.router.navigateByUrl('/');
return;
}
void this.loadUserInfo();
}
protected logout(): void {
this.fusionAuth.logout();
}
private async loadUserInfo(): Promise<void> {
this.isFetchingUserInfo.set(true);
try { this.userInfo.set(await this.fusionAuth.getUserInfo<UserInfo>()); }
catch (error) { console.error('Unable to fetch FusionAuth user info', error);}
finally { this.isFetchingUserInfo.set(false); }
}
}
Test Authentication#
-
Open a private browser window so you don't retain your login status from previous sections.
-
Navigate to the Angular app at http://localhost:3000.

-
Click the Login button. Your browser should redirect to FusionAuth at
http://localhost:9011.
-
Authenticate with the credentials for the user created in
backend_fusionauth/kickstart/kickstart.json:- Username:
richard@example.com - Password:
password
- Username:
FusionAuth validates the credentials, then redirects back to the redirectUri set in src/app/app.config.ts. The homepage checks whether the user is logged in. After a successful login, the app navigates to the account page.
Right now, you should see the account page containing the placeholder text Your note will display here:

Next, you'll replace the placeholder with a note for each user.
Add a Note for Each User#
FusionAuth gives every user a unique Id. In this section, you use that Id to keep a separate note for each user.
Update the Account Page#
Open src/app/account.ts and replace the file contents with the following code to:
- read the user's Id from the
subfield of the user info the SDK fetches from FusionAuth - load the user's saved note, or start a new note with a greeting
- save the note under a key that contains the user's Id
import { Component, Inject, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { FusionAuthService } from '@fusionauth/angular-sdk';
import type { UserInfo } from '@fusionauth/angular-sdk';
import { Router } from '@angular/router';
@Component({
selector: 'app-account',
imports: [FormsModule],
template: `
@if (fusionAuth.isLoggedInSignal() && !isFetchingUserInfo()) {
<header class="titlebar">
<span class="white">{{ userInfo()?.email }}</span>
<button class="button" type="button" (click)="logout()">Logout</button>
</header>
<main class="centerContainer">
<h2>Your note</h2>
<textarea class="note" [(ngModel)]="note" (input)="saved.set(false)"></textarea>
<button class="button" type="button" (click)="saveNote()">Save note</button>
@if (saved()) {
<p>Saved</p>
}
</main>
}
`,
})
export class Account {
protected readonly isFetchingUserInfo = signal(false);
protected readonly userInfo = signal<UserInfo | null>(null);
protected readonly saved = signal(false);
protected note = '';
constructor(
protected readonly fusionAuth: FusionAuthService,
@Inject(Router) private readonly router: Router,
) {
if (!this.fusionAuth.isLoggedIn()) {
void this.router.navigateByUrl('/');
return;
}
void this.loadUserInfo();
}
protected logout(): void {
this.fusionAuth.logout();
}
protected saveNote(): void {
localStorage.setItem(this.noteKey(), this.note);
this.saved.set(true);
}
// sub is the user's FusionAuth Id, so each user gets their own note
private noteKey(): string {
return `note-${this.userInfo()?.sub}`;
}
private async loadUserInfo(): Promise<void> {
this.isFetchingUserInfo.set(true);
try {
const info = await this.fusionAuth.getUserInfo<UserInfo>();
this.userInfo.set(info);
this.note = localStorage.getItem(this.noteKey()) ?? `Hello ${info.given_name ?? info.email}! This note is yours alone.`;
}
catch (error) { console.error('Unable to fetch FusionAuth user info', error); }
finally { this.isFetchingUserInfo.set(false); }
}
}
The app saves notes in the browser's localStorage, so they stay in this browser only. A production app would save them in a database, using the same user Id to look them up.
Test the Notes#
-
Browse to the account page at http://localhost:3000/account. The note starts with a greeting that uses your first name.

-
Edit the note, click Save note , and reload the page. Your note is still there.
-
Click Logout , then Login . On the FusionAuth login page, click Create an account and register a second user with any email address and password.
-
The second user gets a new note, without Richard's text. The registration form doesn't ask for a name, so the greeting uses the email address instead. Log out and log in as
richard@example.comagain to see Richard's note.
Summary#
In this QuickStart, FusionAuth handled login for your Angular app:
- The Angular SDK sent users to the FusionAuth login page and brought them back to the app after login, so the app never saw their passwords.
- The account page used the SDK to send logged-out users back to the homepage.
- After login, the account page used the SDK to fetch the user's details from FusionAuth, including the unique user Id that keeps each note separate.
Next Steps#
This is a quick introduction to using FusionAuth for user authentication. To learn more about integrating FusionAuth with your product, see Get Started.
FusionAuth has many features (including Social Login, Single Sign-On, Passkeys, Multi-factor Authentication), most of which are free. Some require additional licensing. For details, see the pricing page.
For information on the Angular SDK, see the GitHub documentation.
You can ask general questions in the FusionAuth forum.
Related
QuickStart a React Web App with FusionAuth.
QuickStart a Vue.js Web App with FusionAuth.
Explore step-by-step single-page application QuickStart guides from FusionAuth to seamlessly integrate authentication into your application.
Learn how to add login, logout, and registration to your Angular application with the FusionAuth Angular SDK.