Integrate Hanko with Fresh
In this guide you will learn how to use the hanko-elements web components with your Fresh application.
Add <hanko-auth>
component
To provide a login interface in your app, use the <hanko-auth>
web component. Due to an
issue in Fresh, we’re using a browser script to load the web elements.
Call it with the URL of the Hanko API as an argument to register the <hanko-auth>
element with
the browser’s CustomElementRegistry
.
If you are using Hanko Cloud, you can find the API URL on your project dashboard. If you are self-hosting you need to provide the URL of your running Hanko backend.
Add <hanko-events>
component
The <hanko-events>
component provides a convenient way to subscribe to specific
events without displaying any UI elements.
The other hanko-elements will also dispatch these events.
Unfortunately, in the current state of Fresh, there is no added benefit on using because, you cannot leverage the framework event system to handle the dispatched events.
Add <hanko-profile>
To provide a page where users can manage their email addresses, password and passkeys, use the <hanko-profile>
web
component. Just as with the <hanko-auth>
component, import the hanko elements via a native script.
Implement logout
Use the Hanko client to logout. The code below use a custom event to trigger the logout:
Customize component styles
The styles of the hanko-auth
and hanko-profile
can be customized using CSS variables and parts. See our guide
on customization here.
Authenticate backend requests
If you want to authenticate requests in your own backend, please view our backend guide.