Hanko Fullstack 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 comprehensive guide demonstrates integrating Hanko authentication into your fullstack application using the
@teamhanko/hanko-elements
package. You’ll learn to set up authentication components, implement session management, secure routes with middleware, and handle user data across both client and server-side contexts.Key Technologies:- Modern fullstack framework with TypeScript,
- Server-side rendering capabilities
- Hanko Elements
- Hanko Cloud Console
- Session management
- Middleware protection
- Node.js installed on your system
- Basic knowledge of your chosen fullstack framework
- A Hanko Cloud account (sign up at https://cloud.hanko.io/signup)
- Install and configure Hanko Elements package for your framework
- Set up HankoAuth component with session event handling and navigation
- Create HankoProfile component for user credential management
- Implement logout functionality with proper session cleanup and redirects
- Secure routes using framework-specific middleware with session validation
- Retrieve user data both client-side and server-side using appropriate APIs
- Handle authentication redirects, error states, and edge cases
- Configure server-side rendering integration and hydration
- Customize component appearance and behavior for your application
Create a Nuxt application
First, create a new Nuxt.js application using the official Nuxt starter template. This command sets up a complete Nuxt project with TypeScript support and all necessary dependencies. Run the following command to create a new Nuxt application:Install @nuxtjs/hanko
Use the @nuxtjs/hanko
module to integrate Hanko authentication. It provides pre-built components (hanko-auth
, hanko-events
, hanko-profile
), server middleware for route protection, and Vue composables for easy authentication management.
Install the module as a development dependency:
Set up your Hanko project
Before integrating Hanko into your application, you need to create a Hanko project in the cloud console. This project will provide you with an API URL and manage your authentication settings. Go to the Hanko Console and create a project for this application.During project creation, make sure to set the
APP URL
to your development URL (typically http://localhost:3000/). This ensures proper CORS configuration and redirect handling.Add the Hanko API URL
After creating your Hanko project, you’ll receive a unique API URL. This URL is used to communicate with Hanko’s authentication services. TheNUXT_PUBLIC_
prefix makes this environment variable accessible in both server and client-side code.
Retrieve the API URL from the Hanko Console and add it to your environment file:
.env
If you are self-hosting you need to provide the URL of your running Hanko
backend.
Configure Nuxt module
Next, register the Hanko module in your Nuxt configuration and set up authentication behavior. This configuration defines where users should be redirected after login/logout and sets up the module with your API URL. Add the@nuxtjs/hanko
module to your nuxt.config.ts
file:
nuxt.config.ts
hanko
section to your nuxt.config.ts
file. For all overrides please refer to module’s repository.
Using Hanko ComponentsYou can now use the components anywhere in your app (
<hanko-auth>
, <hanko-events>
, <hanko-profile>
). These will render only on client-side and all the props you can pass are strongly typed.If you prefer not to auto-register these components, especially if you plan to use Hanko exclusively on the server side or wish to handle component registration programmatically, you can disable this feature. To do so, set the registerComponents
option to false in your nuxt.config.ts
file:nuxt.config.ts
Setup Nuxt pages
Nuxt uses file-based routing, where each file in thepages/
directory becomes a route. To enable this routing system, add the NuxtPage
component to your main application template.
Update your app.vue
file to use the Nuxt Page Router:
app.vue
/pages
and in there we will create index.vue
and dashboard.vue
.
Add <hanko-auth>
component
The <hanko-auth>
web component provides a complete login and registration interface with passwordless authentication. The hanko-logged-out
middleware ensures that already authenticated users are automatically redirected to the dashboard.
Create your login page at pages/index.vue
:
pages/index.vue
Alternative: Custom redirect handling
If you need more control over post-login behavior, you can use the<hanko-events>
component to listen for authentication events and implement custom logic.
Here’s an alternative approach with custom redirect handling:
pages/index.vue
Define event callbacks
Hanko emits various authentication events that you can listen to for custom application logic. These events include session creation, updates, and destruction. Add the<hanko-events>
component to subscribe to authentication events:
pages/index.vue

Add <hanko-profile>
The <hanko-profile>
component provides a user-friendly interface for managing authentication credentials. Users can add/remove email addresses, register new passkeys, and manage their authentication methods.
Create a dashboard page at pages/dashboard.vue
:
pages/dashboard.vue

Implement logout functionality
To log users out, use the@nuxtjs/hanko
module’s built-in composable useHanko
and call the logout
method.
Secure dashboard page that combines profile management with logout functionality, protected by hanko-logged-in middleware and using the useHanko composable for session management
pages/dashboard.vue
useHanko() composableThe
useHanko
composable provides access to the Hanko SDK which in turn allows access to the Hanko API, e.g. for accessing the current user info.
The composable is auto-imported across the app and can simply be used with useHanko()
anywhere in your code.Customize component styles
You can customize the appearance ofhanko-auth
and hanko-profile
components using CSS variables and parts. Refer to our customization guide.
The styles can be scoped to the login/profile page to ensure they dont affect other parts to the app.
Securing routes with middleware
Use thehanko-logged-in
middleware to secure any route and force unauthenticated users to redirect back to the login
redirect we set in the nuxt.config.ts
.
Page metadata configuration that applies the hanko-logged-in middleware to protect routes from unauthorized access
@nuxtjs/hanko
. After decoding and validating the session token for the request, a new hanko
property is added to the event context.
You can check the value of event.context.hanko
to see if the request was authenticated. The user’s id is accessible though the sub
claim/property.
Server-side API endpoint example that demonstrates how to access authenticated user information through the event context, with proper error handling for unauthorized requests
/server/api/endpoint.ts
Try it yourself
Nuxt example
Full source code available on our GitHub