Learn how to quickly add authentication and user profile in your Remix app using Hanko.
@teamhanko/hanko-elements
package. You’ll learn to set up authentication components, implement session management, secure routes with middleware, and handle user data across both client and server-side contexts.Key Technologies: Modern fullstack framework with TypeScript, server-side rendering capabilities, Hanko Elements, Hanko Cloud Console, session management, and middleware protectionPrerequisites: Node.js, basic knowledge of your chosen fullstack framework, Hanko Cloud account (free at cloud.hanko.io)Integration Tasks You’ll Complete:@teamhanko/hanko-elements
hanko-auth
, hanko-profile
) and a JavaScript SDK.
Install the package:
APP URL
to your development URL (typically http://localhost:5173/ for Remix)..env
file:
@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:
components
folder with two files: HankoAuth.tsx
and HankoProfile.tsx
.
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.
HankoProfile
component allows users to manage their email addresses and passkeys.
For more information see the Profile Component documentation.
/routes
folder. You’ll need _index.tsx
for the login page and dashboard.tsx
for the user dashboard.
Create the main login route:
/
to see the <HankoAuth>
, and to /dashboard
to see the <HankoProfile>
.
They should look something like this👇
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.LogoutButton.tsx
:
hanko-auth
and hanko-profile
components using CSS variables and parts. Refer to our customization guide.
app/services/auth.server.ts
: