> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hanko.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Hanko Elements Auth component guide

> A Web Component that handles user login and user registration.

<div class="hidden">
  **Hanko Elements Auth Component 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 demonstrates how to implement the `<hanko-auth>` web component, which provides a unified authentication interface that handles both user login and registration flows in a single component. You'll learn how to integrate this versatile component into various frameworks and customize its behavior for different use cases.

  **Key Technologies**:

  * Hanko Elements
  * Web Components
  * JavaScript/TypeScript
  * React, Vue, Svelte
  * Next.js, Nuxt, SvelteKit
  * CSS customization
  * Passkeys
  * OAuth SSO
  * Modern authentication methods

  **Prerequisites**:

  * Basic knowledge of frontend development, HTML/JavaScript, your chosen framework
  * Active Hanko account with API access

  **Tasks You'll Complete**:

  * Install and register the Hanko Elements package
  * Configure the `<hanko-auth>` component in your application
  * Implement the component across different frameworks (React, Vue, Svelte)
  * Set up event handlers for authentication state changes
  * Configure component attributes for prefilled values and language settings
  * Handle both login and registration flows in an unified interface
</div>

## Use case

The `<hanko-auth>` component provides a complete authentication solution that combines both login and registration functionality in a single interface. This component is ideal for applications that want to streamline their authentication process without needing separate routes or pages for different authentication flows.

The component automatically handles transitions between login and registration views, providing a seamless user experience throughout the entire authentication process.

If you want to create a dedicated Login page: \
[try out the`<hanko-login>` component](/guides/hanko-elements/login-component).

If you want to create a dedicated Registration page:  \
[try out the `<hanko-registration>` component](/guides/hanko-elements/register-component) .

## Features

|                          |                                                                                             |
| ------------------------ | ------------------------------------------------------------------------------------------- |
| **Login + Registration** | Seamlessly handles both flows in one component.                                             |
| **Passkeys**             | Enables passwordless login with modern device credentials.                                  |
| **Passcodes**            | Useful for email-based login and verification workflows.                                    |
| **2FA**                  | Users can use a TOTP app or security keys.                                                  |
| **OAuth SSO**            | Allows users to log in using third-party identity providers (e.g., Google, Apple).          |
| **SAML SSO**             | Allows users to log in using SAML identity providers (e.g., Entra, Okta, Google Workspace). |
| **Passwords**            | Supports traditional password-based login for broader accessibility.                        |

## Usage

### Markup

```html theme={null}
<hanko-auth></hanko-auth>
```

### Attributes

| Name                 | Description                                                    |
| -------------------- | -------------------------------------------------------------- |
| `prefilled-email`    | Used to prefill the email input field                          |
| `prefilled-username` | Used to prefill the username input field                       |
| `lang`               | Used to specify the language of the content within the element |
| `mode`               | Specify the starting flow, either `registration` or `login`    |

### Adding `<hanko-auth>` component

The following examples show how to integrate the `<hanko-auth>` component in different full-stack and frontend frameworks.

#### Full stack

<Tabs>
  <Tab title="Nextjs (App directory)">
    ```jsx components/HankoAuth.tsx theme={null}
    "use client"

    import { useEffect } from "react";
    import { register } from "@teamhanko/hanko-elements";

    const hankoApi = process.env.NEXT_PUBLIC_HANKO_API_URL;

    export default function HankoAuth() {
      useEffect(() => {
       register(hankoApi)
          .catch((error) => {
            // handle error
          });
      }, []);

    return (
    <hanko-auth />
    );
    }
    ```
  </Tab>

  <Tab title="Nextjs (Pages directory)">
    ```jsx components/HankoAuth.tsx theme={null}
    import { useEffect } from "react";
    import { register } from "@teamhanko/hanko-elements";

    const hankoApi = process.env.NEXT_PUBLIC_HANKO_API_URL;

    export default function HankoAuth() {
      useEffect(() => {
       register(hankoApi)
          .catch((error) => {
            // handle error
          });
    }, []);

    return (
      <hanko-auth />
      );
    }
    ```
  </Tab>

  <Tab title="Nuxt">
    ```html login.vue theme={null}
    <template>
      <hanko-auth />
    </template>
    ```
  </Tab>

  <Tab title="SvelteKit">
    ```html HankoAuth.svelte theme={null}
    <script>
      import { onMount } from "svelte";
      import { goto } from "$app/navigation";
      import { register } from "@teamhanko/hanko-elements";
      import { env } from "$env/dynamic/public";
      const hankoApi = env.PUBLIC_HANKO_API_URL;

      const redirectAfterLogin = () => {
        goto("/dashboard");
      };

      onMount(async () => {
        register(hankoApi).catch((error) => {
          // handle error
        });
      });
    </script>

    <hanko-auth on:onSessionCreated={redirectAfterLogin} />
    ```
  </Tab>
</Tabs>

#### Frontend

<Tabs>
  <Tab title="Create React App">
    ```jsx components/HankoAuth.tsx theme={null}
    import { useEffect } from "react";
    import { register } from "@teamhanko/hanko-elements";

    const hankoApi = process.env.REACT_APP_HANKO_API_URL;

    export default function HankoAuth() {
      useEffect(() => {
        register(hankoApi).catch((error) => {
          // handle error
        });
      }, []);

      return <hanko-auth />;
    }
    ```
  </Tab>

  <Tab title="React with Vite">
    ```jsx components/HankoAuth.tsx theme={null}
    import { useEffect } from "react";
    import { register } from "@teamhanko/hanko-elements";

    const hankoApi = import.meta.env.VITE_HANKO_API_URL;

    export default function HankoAuth() {
      useEffect(() => {
        register(hankoApi).catch((error) => {
          // handle error
        });
      }, []);

      return <hanko-auth />;
    }
    ```
  </Tab>

  <Tab title="Vue">
    ```html HankoAuth.vue theme={null}
    <script setup>
    import { onMounted } from "vue";
    import { register } from "@teamhanko/hanko-elements";

    const hankoApi = process.env.HANKO_API_URL;

    onMounted(() => {
      register(hankoApi)
        .catch((error) => {
          // handle error
        });
    });
    </script>

    <template>
      <hanko-auth />
    </template>
    ```
  </Tab>

  <Tab title="Svelte">
    ```html HankoProfile.svelte theme={null}
    <script>
      import { register } from "@teamhanko/hanko-elements";
      import { onMount } from "svelte";
      import { env } from "$env/dynamic/public";

      const hankoApi = env.PUBLIC_HANKO_API_URL;

      onMount(async () => {
        register(hankoApi).catch((error) => {
          // handle error
        });
      });
    </script>

    <hanko-auth />
    ```
  </Tab>

  <Tab title="JavaScript">
    ```html login.html theme={null}
    <body>
      <hanko-auth />

      <script type="module">
        import { register } from "https://esm.run/@teamhanko/hanko-elements";

        await register(process.env.HANKO_API_URL);
      </script>
    </body>
    ```
  </Tab>
</Tabs>

You should see an interface similar to this 👇

<Frame>
  <img src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/fullstack-guide/next-one.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=cfa08b5e9e30da72781967f53165a313" alt="sign-up" width={500} style={{ borderRadius: '0.5rem' }} data-path="images/fullstack-guide/next-one.png" />
</Frame>

For more detailed instructions on integrating `<hanko-auth>` component with your favorite frameworks, navigate to [quickstart guides](/quickstarts/fullstack).
