Security settings
Account security card combining two-factor status toggle, password rotation form and active browser/device sessions with Revoke.
pnpm dlx shadcn@latest add @haze/security-settings---
import { KeyRound, Laptop, LogOut, ShieldCheck, Smartphone } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Session {
id: string;
device: string;
location: string;
current?: boolean;
mobile?: boolean;
}
interface Props {
id?: string;
sessions?: Session[];
class?: string;
}
const {
id = "haze-security-settings",
sessions = [
{ id: "s1", device: "Chrome on Windows 11", location: "Sarajevo, BA · Active now", current: true },
{ id: "s2", device: "Safari on macOS", location: "Berlin, DE · 2 hours ago" },
{ id: "s3", device: "Haze iOS App", location: "Sarajevo, BA · Yesterday", mobile: true },
],
class: className,
} = Astro.props;
---
<section aria-labelledby={`${id}-title`} data-haze-security-settings class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
<div class="mx-auto max-w-3xl space-y-4">
<div class="rounded-2xl border border-border bg-card p-5 sm:p-6">
<div class="flex flex-wrap items-center justify-between gap-3">
<div class="flex items-center gap-2.5">
<span class="grid size-8 place-items-center rounded-lg border border-frame-success bg-success/10 text-success" aria-hidden="true">
<ShieldCheck class="size-4" />
</span>
<div>
<h2 id={`${id}-title`} class="text-base/6 font-semibold tracking-tight text-foreground">Security & sessions</h2>
<p class="text-xs/5 text-muted-foreground">Authenticator 2FA, password rotation and active devices.</p>
</div>
</div>
<button type="button" data-sec-2fa aria-pressed="true" class="inline-flex h-8 cursor-pointer items-center rounded-lg border border-frame-success bg-success/10 px-3 text-xs font-medium text-success hover:bg-success/20 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">
2FA enabled
</button>
</div>
<form data-sec-pw class="mt-5 grid gap-3 border-t border-border pt-5 sm:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] sm:items-end">
<div class="grid gap-1.5">
<label for={`${id}-cur`} class="text-xs font-medium text-muted-foreground">Current password</label>
<input id={`${id}-cur`} type="password" placeholder="••••••••••••" required class="h-9 rounded-lg border border-frame-input bg-field px-3 text-xs 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>
<div class="grid gap-1.5">
<label for={`${id}-new`} class="text-xs font-medium text-muted-foreground">New password</label>
<input id={`${id}-new`} type="password" placeholder="At least 12 characters" required class="h-9 rounded-lg border border-frame-input bg-field px-3 text-xs 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" class="inline-flex h-9 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-primary px-3.5 text-xs font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
<KeyRound class="size-3.5" aria-hidden="true" />
Update
</button>
</form>
<div class="mt-5 border-t border-border pt-5">
<h3 class="text-xs/4 font-medium tracking-wider text-muted-foreground uppercase">Active sessions</h3>
<ul role="list" class="mt-3 divide-y divide-border rounded-xl border border-border bg-muted/40">
{
sessions.map((s) => (
<li data-sec-sess class="flex flex-wrap items-center justify-between gap-3 p-3.5">
<div class="flex items-center gap-3">
<span class="grid size-8 shrink-0 place-items-center rounded-lg border border-frame bg-field text-muted-foreground" aria-hidden="true">
{s.mobile ? <Smartphone class="size-4" /> : <Laptop class="size-4" />}
</span>
<div>
<p class="flex items-center gap-2 text-sm/5 font-medium text-foreground">
<span>{s.device}</span>
{s.current && <span class="rounded-sm border border-frame-success bg-success/10 px-1.5 py-0.5 text-[0.625rem] font-medium text-success">Current</span>}
</p>
<p class="text-xs/4 text-muted-foreground">{s.location}</p>
</div>
</div>
{!s.current && (
<button type="button" data-sec-revoke={s.device} class="inline-flex h-8 cursor-pointer items-center gap-1 rounded-lg border border-frame bg-field px-2.5 text-xs font-medium text-muted-foreground hover:border-destructive-border hover:text-destructive 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">
<LogOut class="size-3.5" aria-hidden="true" />
Revoke
</button>
)}
</li>
))
}
</ul>
</div>
<p data-sec-status role="status" class="mt-3 min-h-4 text-xs/4 text-muted-foreground"></p>
</div>
</div>
</section>
<script>
function initSecuritySettings() {
document.querySelectorAll<HTMLElement>("[data-haze-security-settings]").forEach((root) => {
if (root.hasAttribute("data-enhanced")) return;
root.setAttribute("data-enhanced", "");
const status = root.querySelector<HTMLElement>("[data-sec-status]");
root.querySelector<HTMLButtonElement>("[data-sec-2fa]")?.addEventListener("click", (ev) => {
const btn = ev.currentTarget as HTMLButtonElement;
const on = btn.getAttribute("aria-pressed") !== "true";
btn.setAttribute("aria-pressed", String(on));
btn.textContent = on ? "2FA enabled" : "Enable 2FA";
if (status) status.textContent = on ? "Two-factor authentication enabled." : "Two-factor authentication paused.";
});
root.querySelector<HTMLFormElement>("[data-sec-pw]")?.addEventListener("submit", (ev) => {
ev.preventDefault();
(ev.currentTarget as HTMLFormElement).reset();
if (status) status.textContent = "Password updated (demo flow).";
});
root.querySelectorAll<HTMLButtonElement>("[data-sec-revoke]").forEach((btn) => {
btn.addEventListener("click", () => {
const dev = btn.dataset.secRevoke ?? "session";
btn.closest("[data-sec-sess]")?.remove();
if (status) status.textContent = `Revoked session on ${dev}.`;
});
});
});
}
initSecuritySettings();
document.addEventListener("astro:page-load", initSecuritySettings);
</script>When to use
- Giving users a single place to manage 2FA, change their password and revoke unfamiliar sessions
- Highlighting the current active device separately from revocable sessions
When not to use
- Running the full 3-step QR and backup-code 2FA enrollment flow; use two-factor-setup
Installation
Add the Haze registry to components.json once, then install Security settings with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/security-settingsnpx shadcn@latest add @haze/security-settingsyarn dlx shadcn@latest add @haze/security-settingsbunx --bun shadcn@latest add @haze/security-settingsFirst 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-security-settings" | Unique prefix for password labels and heading IDs. |
| sessions | Session[] | 3 active sessions | Signed-in devices with current session marker. |
| class | string | – | Extra classes on the outer section. |
Keyboard interactions
- Tab
- Move across the 2FA button, password inputs, Update button and session Revoke buttons
- EnterSpace
- Toggle 2FA, submit a password update or revoke an active session
Accessibility
- The 2FA toggle exposes aria-pressed, and password inputs use explicit labels with type="password".
- Revoking any session removes its row and announces the device name via role="status".
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 "Security settings" with `npx shadcn@latest add @haze/security-settings`. 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 SecuritySettings from "@/components/haze/blocks/security-settings.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/security-settings.md
Customize with real content
Adapt the Haze security-settings block for our product. Replace the demo values of these props with our real content: id, sessions, class. Keep the layout, the heading level rules and these accessibility details: The 2FA toggle exposes aria-pressed, and password inputs use explicit labels with type="password". Revoking any session removes its row and announces the device name via role="status". Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using security-settings, check it fits: use it when giving users a single place to manage 2fa, change their password and revoke unfamiliar sessions; highlighting the current active device separately from revocable sessions. Avoid it when running the full 3-step qr and backup-code 2fa enrollment flow; use two-factor-setup. Alternatives: @haze/two-factor-setup, @haze/settings-page.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.