Skip to main content

Components overview

<hanko-login/>

A Web Component that handles user login.

<hanko-registration/>

A Web Component that handles user registration.

<hanko-auth/>

User login and registration flows combined into a single Web Component.

<hanko-profile/>

A Web Component that allows users to manage their account.

Installation

Add Hanko Elements to your project using your preferred package manager or CDN:

Usage

To use Hanko, import and call the register() function from the hanko-elements module. This enables the web components throughout your application.
For proper functionality, add the <hanko-auth /> element to enable user authentication, and configure the “onSessionCreated” event handler to define post-authentication behavior, such as page redirection. Detailed implementation steps are provided in the following sections.

Importing the module

If you installed via a package manager, you can import the register() function from the @teamhanko/hanko-elements package in your TypeScript or JavaScript file:
For CDN usage, include a script tag with the import statement referencing the CDN-hosted hanko-elements package URL:

Registering the Web Components

After importing the register() function, call it with your Hanko API URL to register the Hanko elements with the browser’s CustomElementRegistry:
You can provide configuration options to customize the behavior and appearance of the components:
  • If cookieSameSite is set to none then your application must be served through HTTPS. The Secure attribute is automatically set to true if your application uses HTTPS.
  • If you want cookies to be available on subdomains, you must set your cookieDomain to your domain prefixed with a .. For example, if your frontend application is running on myapp.com and you want cookies to be available on api.myapp.com, then the cookieDomain value should be .myapp.com.

Embedding the Web Components

After completing the above steps, you can add the web components to your application’s markup. Here’s a basic example:

Advanced guides

Customization

Style Hanko Elements Web Components to match your app’s design.

Internationalization

Support for multiple languages and translation options for a global user base.