Hanko Elements introduction 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 introduces Hanko Elements, a collection of pre-built web components that provide modern authentication functionality. You’ll learn about the available components, their features, and how to get started with integrating the components in your applications.Key Technologies:
- Hanko Elements
- Web Components
- JavaScript/TypeScript
- Passkeys
- OAuth SSO
- 2FA authentication
- CSS customization
- Internationalization
- Modern web frameworks integration
- Basic knowledge of frontend development, HTML/JavaScript, and web components
- Familiarity with your chosen frontend framework and an active Hanko account
- Understand the available Hanko web components and their use cases
- Install and configure Hanko Elements in your project
- Register web components and configure authentication options
- Implement basic authentication flows using pre-built components
- Set up event handling for authentication state management
- Explore customization and internationalization options
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 theregister() 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 theregister() function from the @teamhanko/hanko-elements package in your TypeScript or JavaScript file:
script tag with the import statement referencing the CDN-hosted hanko-elements package URL:
Registering the Web Components
After importing theregister() function, call it with your Hanko API URL to register the Hanko elements with the browser’s CustomElementRegistry:
Cookie options
- If
cookieSameSiteis set tononethen your application must be served through HTTPS. TheSecureattribute is automatically set to true if your application uses HTTPS. - If you want cookies to be available on subdomains, you must set your
cookieDomainto your domain prefixed with a.. For example, if your frontend application is running onmyapp.comand you want cookies to be available onapi.myapp.com, then thecookieDomainvalue should be.myapp.com.