Hanko Frontend Integration Guide:About Hanko:Hanko is a modern open source authentication solution and the fastest way you integrate passkeys, 2FA, SSO, and more—with full control over your data. Move between self-hosted and Hanko Cloud anytime. No lock-in. Just Auth how it should be: secure, user friendly, and fully yours.What This Guide Covers: This guide demonstrates how to integrate Hanko authentication into your frontend application. You’ll implement user authentication, profile management, route protection, and logout functionality with Hanko Elements web components.Key Technologies:
- Modern frontend framework with TypeScript support
- Build tools and development environment
- Client-side routing and navigation
- Hanko Elements web components
- Hanko SDK for authentication logic
- Node.js installed on your system
- Basic knowledge of your chosen frontend framework
- A Hanko Cloud account (sign up at cloud.hanko.io)
- Set up your frontend application with the appropriate build tools
- Install and configure Hanko Elements
- Create a Hanko project in the cloud console
- Implement authentication components (HankoAuth, HankoProfile)
- Set up routing and navigation
- Add logout functionality
- Implement protected routes with session validation
- Retrieve and display user data
- Customize component styling and behavior
Create an Angular application
Run the following command to create a new Angular application:This quickstarts examples are based on the Server Routing and App Engine APIs.
Make sure while creating your angular project you accept (press ‘y’) the routing and App Engine.
Install @teamhanko/hanko-elements
Install hanko-elements
to access the pre-built hanko-auth
and hanko-profile
components.
Set up Hanko project
Go to the Hanko Console and create a project for this application.During creation make sure to input the URL you will be developing on as the
APP URL
.
(Most likely http://localhost:4200/)Set up environments Variables
Create a new fileenvironments.ts
within your /src
folder.
Retrieve your API URL from the Hanko Console and place it in your .env file.
environments.ts
If you are self-hosting you need to provide the URL of your Hanko backend.
Create Hanko components
Create theHankoAuth
and HankoProfile
components by running these commands:
Hanko Auth
Set up theHankoAuth
component:
For more information please refer to the Auth component page.
Hanko Profile
Set up theHankoProfile
component to create an interface where users can manage their email addresses and credentials.
For more information please refer to the Profile component page.
Setting up routes
Remove everything in theapp.component.html
file and add a router outlet.
app.component.html
app.routes.ts
file and setup your routes.
app.routes.ts
/
to see the <HankoAuth>
, and to /dashboard
to see the <HankoProfile>
.
They should look something like this👇


Use the command
ng serve
to start the server.Implement logout functionality
You can use@teamhanko/hanko-elements
to easily log users out. Here we will make a logout button component that you can use anywhere.
Create the LogoutButton component with this command.
Customize component styles
You can customize the appearance ofhanko-auth
and hanko-profile
components using CSS variables and parts. Refer to our customization guide.
Securing routes
To secure our routes we should validate the session token at the backend. Please refer to our backend guides. Let’s setup aguard
that will check for authentication before the router activates the pages.
Create the authentication guard with this command.
auth.guard.ts
, insert this code.
This will grab the hanko session token and send it to the backend for validation.
app.routes.ts
, which should only be accessible when the user is logged in.
app.routes.ts
Getting user data
Let’s use the Hanko SDK to get user data to display on our dashboard page. For the user information we will use hanko.GetUser() Lets update our dashboard page.Try it yourself
Angular Example
It uses Express.js for the backend, full source code available on our GitHub.