Login and sign up
Sign-in and sign-up demo with sample provider buttons, an email field, and a six-digit code step.
pnpm dlx shadcn@latest add @haze/auth-login---
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="[email protected]" 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">[email protected]</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>When to use
- Prototyping sign-in and sign-up modes in one compact card
- Demonstrating the transition from email entry to a six-digit code field
When not to use
- Authenticating or enrolling users in a live service
- You only need a simple static password sign-in form; use auth-sign-in-card
Installation
Add the Haze registry to components.json once, then install Login and sign up with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/auth-loginnpx shadcn@latest add @haze/auth-loginyarn dlx shadcn@latest add @haze/auth-loginbunx --bun shadcn@latest add @haze/auth-loginFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | "haze-auth-login" | Unique prefix for form labels and heading IDs. |
| brand | string | "Haze UI" | Wordmark text shown beside the Haze logo. |
| class | string | – | Extra classes on the outer section. |
Keyboard interactions
- Tab
- Move across mode buttons, sample provider buttons, and form fields
- EnterSpace
- Activate the focused button. Enter in a form field submits the current step.
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.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
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": "http://localhost:4329/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: http://localhost:4329/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.
Dependencies
- npm: @lucide/astro
- @haze/logo-mark
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.