# Login and sign up

> Sign-in and sign-up demo with sample provider buttons, an email field, and a six-digit code step.

- Kind: block · Category: Auth · Interactivity: script
- Install: `npx shadcn@latest add @haze/auth-login`
- File: `src/components/haze/blocks/auth-login.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/logo-mark, @haze/utils
- Docs page: https://hazeui.com/blocks/auth-login

## Use when
- Prototyping sign-in and sign-up modes in one compact card
- Demonstrating the transition from email entry to a six-digit code field

## Avoid when
- Authenticating or enrolling users in a live service
- You only need a simple static password sign-in form; use auth-sign-in-card

## Alternatives
- [auth-sign-in-card](https://hazeui.com/blocks/auth-sign-in-card.md)
- [otp-input](https://hazeui.com/ui/otp-input.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` | "haze-auth-login" | no | Unique prefix for form labels and heading IDs. |
| brand | `string` | "Haze UI" | no | Wordmark text shown beside the Haze logo. |
| class | `string` |  | no | Extra classes on the outer section. |

## Accessibility
- Sign in and Sign up buttons expose aria-pressed and reveal the Full name field in sign-up mode.
- Submitting the email step moves focus to the demo code field. Invalid codes are announced and keep focus on the field.
- Key Tab: Move across mode buttons, sample provider buttons, and form fields
- Key Enter / Space: Activate the focused button. Enter in a form field submits the current step.

## Agent prompts

### Install and use

Install the Haze UI block "Login and sign up" with `npx shadcn@latest add @haze/auth-login`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import AuthLogin from "@/components/haze/blocks/auth-login.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/blocks/auth-login.md

### Customize with real content

Adapt the Haze auth-login block for our product. Replace the demo values of these props with our real content: id, brand, class. Keep the layout, the heading level rules and these accessibility details: Sign in and Sign up buttons expose aria-pressed and reveal the Full name field in sign-up mode. Submitting the email step moves focus to the demo code field. Invalid codes are announced and keep focus on the field. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using auth-login, check it fits: use it when prototyping sign-in and sign-up modes in one compact card; demonstrating the transition from email entry to a six-digit code field. Avoid it when authenticating or enrolling users in a live service; you only need a simple static password sign-in form; use auth-sign-in-card. Alternatives: @haze/auth-sign-in-card, @haze/otp-input.

## Example requests that should lead here
- Add a sign-in and sign-up demo with sample Google and GitHub buttons and a six-digit code step

## Source

```astro
---
import { ArrowRight, KeyRound, Mail } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
import LogoMark from "../ui/logo-mark.astro";

interface Props {
  id?: string;
  brand?: string;
  class?: string;
}

const { id = "haze-auth-login", brand = "Haze UI", class: className } = Astro.props;
---

<section aria-labelledby={`${id}-title`} data-haze-auth-login class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
  <div class="mx-auto max-w-md rounded-2xl border border-border bg-card p-6 shadow-float sm:p-8">
    <div class="flex flex-wrap items-center justify-between gap-2">
      <LogoMark name={brand} shape="haze" class="text-foreground" />
      <div role="group" aria-label="Authentication mode" class="inline-flex rounded-lg border border-frame bg-muted p-0.5">
        <button type="button" data-al-mode="signin" aria-pressed="true" class="inline-flex h-7 cursor-pointer items-center rounded-md px-2.5 text-xs font-medium text-muted-foreground aria-pressed:bg-card aria-pressed:text-foreground aria-pressed:shadow-key focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">Sign in</button>
        <button type="button" data-al-mode="signup" aria-pressed="false" class="inline-flex h-7 cursor-pointer items-center rounded-md px-2.5 text-xs font-medium text-muted-foreground aria-pressed:bg-card aria-pressed:text-foreground aria-pressed:shadow-key focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">Sign up</button>
      </div>
    </div>

    <h2 id={`${id}-title`} data-al-heading class="mt-6 text-xl/7 font-semibold tracking-tight text-foreground">Sign in with email code</h2>
    <p class="mt-1 text-xs/5 text-muted-foreground"><strong class="font-semibold text-foreground">Demo only.</strong> Use a sample work email to try the flow.</p>

    <div data-al-step="email">

      <div class="mt-5 grid grid-cols-2 gap-2">
        <button type="button" data-al-oauth="Google" class="inline-flex h-9 cursor-pointer items-center justify-center rounded-lg border border-frame bg-field text-xs font-medium text-foreground hover:border-frame-strong hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">Google</button>
        <button type="button" data-al-oauth="GitHub" class="inline-flex h-9 cursor-pointer items-center justify-center rounded-lg border border-frame bg-field text-xs font-medium text-foreground hover:border-frame-strong hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">GitHub</button>
      </div>

      <div class="my-5 flex items-center gap-3 text-[0.6875rem] text-muted-foreground">
        <span class="h-px flex-1 bg-border"></span>
        <span>or continue with email</span>
        <span class="h-px flex-1 bg-border"></span>
      </div>

      <form data-al-form class="grid gap-3.5">
        <div data-al-name-wrap hidden class="grid gap-1.5">
          <label for={`${id}-name`} class="text-xs font-medium text-foreground">Full name</label>
          <input id={`${id}-name`} type="text" placeholder="Nina Patel" class="h-10 rounded-lg border border-frame-input bg-field px-3 text-sm text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground" />
        </div>
        <div class="grid gap-1.5">
          <label for={`${id}-email`} class="text-xs font-medium text-foreground">Work email</label>
          <input id={`${id}-email`} data-al-email type="email" required value="nina@tidewell.dev" class="h-10 rounded-lg border border-frame-input bg-field px-3 text-sm text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground" />
        </div>
        <button type="submit" disabled class="inline-flex h-10 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-primary text-sm font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring disabled:cursor-not-allowed disabled:opacity-45 transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
          <Mail class="size-4" aria-hidden="true" />
          <span>Continue with email</span>
          <ArrowRight class="size-4" aria-hidden="true" />
        </button>
      </form>
    </div>

    <form data-al-step="code" hidden class="mt-6 space-y-4">
      <div class="flex items-center gap-2 text-muted-foreground">
        <KeyRound class="size-4" aria-hidden="true" />
        <span class="text-xs font-medium">Email code demo</span>
      </div>
      <p class="wrap-anywhere text-sm/6 text-muted-foreground">Sample email <strong data-al-preview-email class="text-foreground">nina@tidewell.dev</strong></p>
      <div class="grid gap-1.5">
        <label for={`${id}-code`} class="text-xs font-medium text-foreground">Demo code</label>
        <p id={`${id}-code-hint`} class="text-xs/5 text-muted-foreground">Enter any six digits to complete the demo.</p>
        <input id={`${id}-code`} data-al-code type="text" required pattern="[0-9]{6}" inputmode="numeric" maxlength="6" aria-describedby={`${id}-code-hint ${id}-code-error`} class="h-10 rounded-lg border border-frame-input bg-field px-3 font-mono text-sm tracking-[0.25em] text-foreground aria-invalid:border-destructive-border focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground aria-invalid:focus-visible:ring-destructive/24" />
        <p id={`${id}-code-error`} data-al-error role="alert" class="text-xs/5 text-destructive"></p>
      </div>
      <div class="flex items-center gap-2">
        <button type="button" data-al-back class="inline-flex h-9 cursor-pointer items-center rounded-lg border border-frame bg-field px-3 text-xs font-medium text-muted-foreground hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">Back</button>
        <button type="submit" class="inline-flex h-9 flex-1 cursor-pointer items-center justify-center rounded-lg bg-primary px-4 text-xs font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">Finish demo</button>
      </div>
    </form>

    <p data-al-status role="status" class="mt-4 min-h-4 text-xs/4 text-muted-foreground"></p>
  </div>
</section>

<script>
  function initAuthLogins() {
    document.querySelectorAll<HTMLElement>("[data-haze-auth-login]").forEach((root) => {
      if (root.hasAttribute("data-enhanced")) return;
      const heading = root.querySelector<HTMLElement>("[data-al-heading]");
      const nameWrap = root.querySelector<HTMLElement>("[data-al-name-wrap]");
      const emailIn = root.querySelector<HTMLInputElement>("[data-al-email]");
      const previewEmail = root.querySelector<HTMLElement>("[data-al-preview-email]");
      const stepEmail = root.querySelector<HTMLElement>('[data-al-step="email"]');
      const emailForm = root.querySelector<HTMLFormElement>("[data-al-form]");
      const codeForm = root.querySelector<HTMLFormElement>('[data-al-step="code"]');
      const code = root.querySelector<HTMLInputElement>("[data-al-code]");
      const error = root.querySelector<HTMLElement>("[data-al-error]");
      const status = root.querySelector<HTMLElement>("[data-al-status]");
      const emailSubmit = emailForm?.querySelector<HTMLButtonElement>("[type='submit']");
      if (!heading || !nameWrap || !emailIn || !previewEmail || !stepEmail || !emailForm || !emailSubmit || !codeForm || !code || !error || !status) return;
      root.setAttribute("data-enhanced", "");
      emailSubmit.disabled = false;

      let signingUp = false;
      const clearError = () => {
        code.removeAttribute("aria-invalid");
        error.textContent = "";
      };
      const showEmailStep = () => {
        codeForm.reset();
        clearError();
        codeForm.hidden = true;
        stepEmail.hidden = false;
        status.textContent = "";
      };

      const modes = root.querySelectorAll<HTMLButtonElement>("[data-al-mode]");
      modes.forEach((button) => {
        button.addEventListener("click", () => {
          signingUp = button.dataset.alMode === "signup";
          modes.forEach((mode) => mode.setAttribute("aria-pressed", String(mode === button)));
          nameWrap.hidden = !signingUp;
          heading.textContent = signingUp ? "Create your workspace account" : "Sign in with email code";
          showEmailStep();
        });
      });

      emailForm.addEventListener("submit", (event) => {
        event.preventDefault();
        previewEmail.textContent = emailIn.value;
        stepEmail.hidden = true;
        codeForm.hidden = false;
        status.textContent = "";
        code.focus();
      });

      root.querySelector<HTMLButtonElement>("[data-al-back]")?.addEventListener("click", () => {
        showEmailStep();
        emailIn.focus();
      });
      code.addEventListener("input", () => {
        clearError();
        status.textContent = "";
      });
      code.addEventListener("invalid", (event) => {
        event.preventDefault();
        code.setAttribute("aria-invalid", "true");
        error.textContent = "Enter six digits to continue.";
        code.focus();
      });
      codeForm.addEventListener("submit", (event) => {
        event.preventDefault();
        status.textContent = signingUp ? "Sign-up demo complete." : "Sign-in demo complete.";
      });
      root.querySelectorAll<HTMLButtonElement>("[data-al-oauth]").forEach((btn) => {
        btn.addEventListener("click", () => {
          status.textContent = `${btn.dataset.alOauth} selected for this demo.`;
        });
      });
    });
  }
  initAuthLogins();
  if (!document.documentElement.hasAttribute("data-haze-auth-login-listener")) {
    document.documentElement.setAttribute("data-haze-auth-login-listener", "");
    document.addEventListener("astro:page-load", initAuthLogins);
  }
</script>
```
