Skip to main content

Create a Remix application

Create a new Remix application using the official starter template. Run the following command to create a new Remix application:

Install @teamhanko/hanko-elements

The Hanko Elements package provides pre-built authentication components (hanko-auth, hanko-profile) and a JavaScript SDK. Install the package:

Set up your Hanko project

Create a Hanko project in the Cloud Console to get your API URL. Go to the Hanko Console and create a project for this application.
Set the APP URL to your development URL (typically http://localhost:5173/ for Remix).

Add the Hanko API URL

Add your Hanko API URL to your environment file. In Remix, environment variables without a public prefix are server-side only. Retrieve the API URL from the Hanko Console and add it to your .env file:
.env
If you are self-hosting you need to provide the URL of your running Hanko backend.

Create client-side utilities

The @teamhanko/hanko-elements package only works client-side. Use Remix’s .client.ts file convention to ensure code only runs in the browser. Create a client-side utility file:
utils/hanko.client.ts

Create Hanko components

Create a components folder with two files: HankoAuth.tsx and HankoProfile.tsx.

Hanko Auth

The HankoAuth component provides login and registration functionality. It uses Remix’s loader to pass the API URL from server to client, and handles the onSessionCreated event for post-login navigation. For more information see the Auth component documentation.
components/HankoAuth.tsx

Hanko Profile

The HankoProfile component allows users to manage their email addresses and passkeys. For more information see the Profile component documentation.
components/HankoProfile.tsx

Setup your routes

Create your routes in the /routes folder. You’ll need _index.tsx for the login page and dashboard.tsx for the user dashboard. Create the main login route:
routes/_index.tsx
Create the dashboard route:
routes/dashboard.tsx
By now you should be able to go to / to see the <HankoAuth>, and to /dashboard to see the <HankoProfile>. They should look something like this👇
sign upprofile page
If HankoAuth is not loading please restart the application as it might’ve not loaded the .env correctly the first time.

HankoProfile will only look like the picture while you are logged in.

Implement logout functionality

Create a logout button using the Hanko SDK’s logout method. Create LogoutButton.tsx:
components/LogoutButton.tsx

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.

Securing routes

Protect routes by validating session tokens in loader functions. Create a server-side authentication utility to handle session validation. Create app/services/auth.server.ts:
app/services/auth.server.ts
Use the authentication service in your protected routes. Update your dashboard route to validate sessions:
app/routes/dashboard.tsx

Try it yourself

Remix example

Full source code available on our GitHub