Integrate Hanko with Vue
Learn how to quickly add authentication and user profile in your Vue app using Hanko.
Install @teamhanko/hanko-elements
Once you’ve initialized your Vue app, installing hanko-elements provides you with access to the prebuilt components: hanko-auth
, hanko-profile
and hanko-events
.
Add the Hanko API URL
Retrieve the API URL from the Hanko console and place it in your .env file.
If you are self-hosting you need to provide the URL of your running Hanko backend.
Configure component resolution
Vue needs to know which elements to treat as custom elements, otherwise it will issue a warning regarding component
resolution. To do so, provide a predicate function that determines which elements are to be considered custom elements
to compilerOptions.isCustomElement
in your configuration:
Add <hanko-auth>
component
The <hanko-auth>
web component adds a login interface to your app. Begin by importing the register function from @teamhanko/hanko-elements
into your Vue component. Call it with the Hanko API URL as an argument to register <hanko-auth>
with the browser’s CustomElementRegistry. Then use the element in your component template.
By now, your sign-up and sign-in features should be working. You should see an interface similar to this 👇
Add <hanko-profile>
component
The <hanko-profile>
component provides an interface, where users can manage their email addresses and passkeys.
It should look like this 👇
Implement logout functionality
You can use @teamhanko/hanko-elements
to easily manage user logouts. Below, we make a logout button component that you can use anywhere.
Customize component styles
You can customize the appearance of hanko-auth
and hanko-profile
components using CSS variables and parts. Refer to our customization guide.
Authenticate backend requests
To authenticate requests on your backend with Hanko, refer to our backend guide.
Try it yourself
Vue example
It uses Express.js for the backend, full source code available on our GitHub.