{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "login-terminal",
  "type": "registry:component",
  "title": "Login Terminal",
  "description": "A developer sign-in told as a terminal session: prompt lines type in, a one-time device code appears with a copy button, a pulsing waiting line counts down to expiry, plus a token form for headless machines.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "auth",
    "cli",
    "terminal",
    "device code",
    "developer",
    "login",
    "token"
  ],
  "docs": "https://hyperblur.dev/effects/login-terminal",
  "files": [
    {
      "path": "registry/hyperblur/login-terminal.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/login-terminal.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type LoginTerminalStatus = \"waiting\" | \"approved\" | \"expired\";\n\nexport interface LoginTerminalProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\" | \"onSubmit\"> {\n  title?: string;\n  subtitle?: string;\n  command?: string;\n  code?: string;\n  verifyUrl?: string;\n  user?: string;\n  expiresIn?: number;\n  status?: LoginTerminalStatus;\n  defaultStatus?: LoginTerminalStatus;\n  onStatusChange?: (status: LoginTerminalStatus) => void;\n  onCodeCopy?: (code: string) => void;\n  onSubmit?: (values: { token: string }) => boolean | void | Promise<boolean | void>;\n  tokenPrefix?: string;\n  accent?: string;\n}\n\nconst css = `\n.hb-qh9 {\n  --hb-qh9-accent: #4ade80;\n  --hb-qh9-mono: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  overflow: hidden;\n  container-type: inline-size;\n  background: #08090a;\n  color: #ededed;\n  font-family: inherit;\n  padding: clamp(64px, 9cqw, 112px) 20px;\n}\n.hb-qh9 *, .hb-qh9 *::before, .hb-qh9 *::after { box-sizing: border-box; }\n.hb-qh9::before { content: \"\"; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px) 0 0 / 32px 32px, linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px) 0 0 / 32px 32px; mask: radial-gradient(ellipse 60% 60% at 70% 50%, #000, transparent 75%); }\n.hb-qh9-inner { position: relative; max-width: 1120px; margin: 0 auto; display: grid; gap: 40px; align-items: center; }\n.hb-qh9-kicker { font-family: var(--hb-qh9-mono); font-size: 12px; color: var(--hb-qh9-accent); letter-spacing: .04em; }\n.hb-qh9-title { margin: 14px 0 12px; font-size: clamp(30px, 4.4cqw, 44px); line-height: 1.05; letter-spacing: -.03em; font-weight: 600; }\n.hb-qh9-sub { margin: 0; max-width: 420px; color: #8f8f8f; font-size: 15px; line-height: 1.6; }\n.hb-qh9-steps { list-style: none; margin: 26px 0 0; padding: 0; display: grid; gap: 12px; counter-reset: hb-qh9-n; }\n.hb-qh9-steps li { display: flex; gap: 12px; align-items: baseline; font-size: 14px; color: #a1a1a1; counter-increment: hb-qh9-n; }\n.hb-qh9-steps li::before { content: counter(hb-qh9-n, decimal-leading-zero); font-family: var(--hb-qh9-mono); font-size: 12px; color: #555; }\n.hb-qh9-steps code { font-family: var(--hb-qh9-mono); font-size: 13px; color: #ededed; background: #141414; border: 1px solid #222; padding: 1px 6px; border-radius: 6px; }\n.hb-qh9-token { margin-top: 28px; padding-top: 22px; border-top: 1px solid rgba(255,255,255,.07); max-width: 420px; }\n.hb-qh9-tlabel { display: block; font-size: 13px; color: #a1a1a1; margin-bottom: 8px; }\n.hb-qh9-trow { display: flex; gap: 8px; }\n.hb-qh9-tinput { flex: 1; min-width: 0; height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid #262626; background: #0e0e0e; color: #ededed; font-family: var(--hb-qh9-mono); font-size: 13px; outline: none; transition: border-color .2s, box-shadow .2s; }\n.hb-qh9-tinput:focus { border-color: var(--hb-qh9-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-qh9-accent) 18%, transparent); }\n.hb-qh9-tinput[aria-invalid=\"true\"] { border-color: #f87171; }\n.hb-qh9-tbtn { flex: none; height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid #2a2a2a; background: #161616; color: #ededed; font: inherit; font-size: 13.5px; cursor: pointer; transition: background .2s; }\n.hb-qh9-tbtn:hover { background: #1e1e1e; }\n.hb-qh9-tbtn:disabled { cursor: progress; color: #8f8f8f; }\n.hb-qh9-terr { margin: 8px 0 0; font-size: 12.5px; color: #fca5a5; }\n.hb-qh9-tok { margin: 8px 0 0; font-size: 12.5px; color: var(--hb-qh9-accent); }\n.hb-qh9-win { border-radius: 16px; border: 1px solid rgba(255,255,255,.1); background: #0c0d0e; box-shadow: inset 0 1px 0 rgba(255,255,255,.05), 0 40px 100px -40px color-mix(in srgb, var(--hb-qh9-accent) 25%, transparent), 0 30px 60px -30px rgba(0,0,0,.9); overflow: hidden; min-width: 0; }\n.hb-qh9-bar { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; border-bottom: 1px solid rgba(255,255,255,.06); background: #111213; }\n.hb-qh9-light { width: 11px; height: 11px; border-radius: 50%; background: #2a2a2a; }\n.hb-qh9-wtitle { flex: 1; text-align: center; margin-right: 40px; font-family: var(--hb-qh9-mono); font-size: 12px; color: #6f6f6f; }\n.hb-qh9-body { padding: 20px 20px 24px; font-family: var(--hb-qh9-mono); font-size: 13.5px; line-height: 1.75; color: #cfcfcf; min-height: 330px; overflow-x: auto; }\n.hb-qh9-line { display: block; white-space: pre; clip-path: inset(0 100% 0 0); animation: hb-qh9-type var(--hb-qh9-dur, .5s) steps(var(--hb-qh9-steps, 20)) var(--hb-qh9-delay, 0s) forwards; }\n.hb-qh9-pr { color: var(--hb-qh9-accent); }\n.hb-qh9-dim { color: #6f6f6f; }\n.hb-qh9-q { color: #7fb3ff; }\n.hb-qh9-warn { color: #fbbf24; }\n.hb-qh9-codebox { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0 14px; padding: 14px 14px 14px 18px; border-radius: 12px; border: 1px solid color-mix(in srgb, var(--hb-qh9-accent) 35%, transparent); background: color-mix(in srgb, var(--hb-qh9-accent) 6%, #0c0d0e); opacity: 0; animation: hb-qh9-pop .5s cubic-bezier(.2,.7,.2,1) var(--hb-qh9-delay, 0s) forwards; }\n.hb-qh9-code { font-size: clamp(22px, 3.4cqw, 30px); letter-spacing: .18em; font-weight: 600; color: #fff; }\n.hb-qh9-copy { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 9px; border: 1px solid rgba(255,255,255,.12); background: #151617; color: #ededed; font-family: inherit; font-size: 12px; cursor: pointer; transition: background .2s, border-color .2s; }\n.hb-qh9-copy:hover { background: #1c1d1e; border-color: rgba(255,255,255,.2); }\n.hb-qh9-copy[data-copied=\"true\"] { color: var(--hb-qh9-accent); border-color: color-mix(in srgb, var(--hb-qh9-accent) 45%, transparent); }\n.hb-qh9-copy:focus-visible, .hb-qh9-tbtn:focus-visible, .hb-qh9-url:focus-visible { outline: 2px solid var(--hb-qh9-accent); outline-offset: 2px; }\n.hb-qh9-url { color: #ededed; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(255,255,255,.3); border-radius: 3px; }\n.hb-qh9-wait { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; opacity: 0; animation: hb-qh9-pop .4s ease var(--hb-qh9-delay, 0s) forwards; }\n.hb-qh9-spinner::before { content: \"⠋\"; color: var(--hb-qh9-accent); animation: hb-qh9-braille .8s steps(1) infinite; }\n.hb-qh9-pulse { animation: hb-qh9-pulse 1.6s ease-in-out infinite; }\n.hb-qh9-exp { color: #6f6f6f; font-variant-numeric: tabular-nums; }\n.hb-qh9-ok { color: var(--hb-qh9-accent); }\n.hb-qh9-bad { color: #f87171; }\n.hb-qh9-cursor { display: inline-block; width: .6em; height: 1.1em; vertical-align: -.2em; background: var(--hb-qh9-accent); animation: hb-qh9-blink 1s steps(1) infinite; }\n.hb-qh9-res { display: block; animation: hb-qh9-pop .35s ease both; }\n@container (min-width: 860px) {\n  .hb-qh9-inner { grid-template-columns: .85fr 1.15fr; gap: 56px; }\n}\n@keyframes hb-qh9-type { to { clip-path: inset(0 0 0 0); } }\n@keyframes hb-qh9-pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }\n@keyframes hb-qh9-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }\n@keyframes hb-qh9-blink { 50% { opacity: 0; } }\n@keyframes hb-qh9-braille {\n  0% { content: \"⠋\"; } 12.5% { content: \"⠙\"; } 25% { content: \"⠹\"; } 37.5% { content: \"⠸\"; }\n  50% { content: \"⠼\"; } 62.5% { content: \"⠴\"; } 75% { content: \"⠦\"; } 87.5% { content: \"⠧\"; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qh9 *, .hb-qh9 *::before, .hb-qh9 *::after { animation: none !important; transition: none !important; }\n  .hb-qh9-line { clip-path: none; }\n  .hb-qh9-codebox, .hb-qh9-wait { opacity: 1; }\n}\n`;\n\nfunction format(seconds: number) {\n  return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, \"0\")}`;\n}\n\nfunction wait(result: unknown) {\n  return result instanceof Promise ? result : new Promise<unknown>((resolve) => setTimeout(() => resolve(result), 900));\n}\n\nfunction lineStyle(delay: number, text: string) {\n  return { \"--hb-qh9-delay\": `${delay.toFixed(2)}s`, \"--hb-qh9-steps\": Math.max(4, text.length), \"--hb-qh9-dur\": `${Math.min(1.2, 0.02 * text.length + 0.15).toFixed(2)}s` } as React.CSSProperties;\n}\n\nexport function LoginTerminal({\n  title = \"Sign in from your terminal\",\n  subtitle = \"Authorize the Forge CLI with a one-time device code. No passwords in your shell history, and you can revoke the session any time.\",\n  command = \"forge auth login\",\n  code = \"WDJB-MJHT\",\n  verifyUrl = \"https://forge.dev/device\",\n  user = \"mara-k\",\n  expiresIn = 900,\n  status,\n  defaultStatus = \"waiting\",\n  onStatusChange,\n  onCodeCopy,\n  onSubmit,\n  tokenPrefix = \"fg_\",\n  accent = \"#4ade80\",\n  className = \"\",\n  style,\n  ...rest\n}: LoginTerminalProps) {\n  const uid = React.useId();\n  const [inner, setInner] = React.useState<LoginTerminalStatus>(defaultStatus);\n  const current = status ?? inner;\n  const [left, setLeft] = React.useState(expiresIn);\n  const [copied, setCopied] = React.useState(false);\n  const [token, setToken] = React.useState(\"\");\n  const [tokenError, setTokenError] = React.useState(\"\");\n  const [tokenBusy, setTokenBusy] = React.useState(false);\n\n  const update = React.useCallback((next: LoginTerminalStatus) => {\n    setInner(next);\n    onStatusChange?.(next);\n  }, [onStatusChange]);\n\n  React.useEffect(() => {\n    if (current !== \"waiting\" || left <= 0) return;\n    const id = window.setTimeout(() => {\n      if (left <= 1) update(\"expired\");\n      setLeft((s) => s - 1);\n    }, 1000);\n    return () => window.clearTimeout(id);\n  }, [current, left, update]);\n\n  React.useEffect(() => {\n    if (!copied) return;\n    const id = window.setTimeout(() => setCopied(false), 1800);\n    return () => window.clearTimeout(id);\n  }, [copied]);\n\n  async function copy() {\n    let ok = true;\n    try {\n      await navigator.clipboard?.writeText(code);\n    } catch {\n      ok = false;\n    }\n    setCopied(ok);\n    if (ok) onCodeCopy?.(code);\n  }\n\n  async function handleToken(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    if (tokenBusy) return;\n    const value = token.trim();\n    if (!value) return setTokenError(\"Paste a personal access token.\");\n    if (!value.startsWith(tokenPrefix) || value.length < tokenPrefix.length + 20) return setTokenError(`Tokens start with ${tokenPrefix} and are at least ${tokenPrefix.length + 20} characters.`);\n    setTokenError(\"\");\n    setTokenBusy(true);\n    try {\n      const result = await wait(onSubmit ? onSubmit({ token: value }) : true);\n      if (result === false) setTokenError(\"That token was rejected. Check its scopes.\");\n      else update(\"approved\");\n    } catch {\n      setTokenError(\"Couldn't verify the token. Try again.\");\n    }\n    setTokenBusy(false);\n  }\n\n  const host = verifyUrl.replace(\"https://\", \"\").replace(\"http://\", \"\");\n  const l1 = `$ ${command}`;\n  const l2 = \"? How would you like to authenticate? Login with a web browser\";\n  const l4 = `- Press Enter to open ${host} in your browser...`;\n\n  return (\n    <section className={`hb-qh9 ${className}`} style={{ \"--hb-qh9-accent\": accent, ...style } as React.CSSProperties} {...rest}>\n      <style href=\"hb-login-terminal\" precedence=\"default\">{css}</style>\n      <div className=\"hb-qh9-inner\">\n        <div>\n          <span className=\"hb-qh9-kicker\">~/ forge cli</span>\n          <h2 className=\"hb-qh9-title\">{title}</h2>\n          <p className=\"hb-qh9-sub\">{subtitle}</p>\n          <ol className=\"hb-qh9-steps\">\n            <li><span>Run <code>{command}</code> in any project.</span></li>\n            <li><span>Open <a className=\"hb-qh9-url\" href={verifyUrl}>{host}</a> and enter the code.</span></li>\n            <li><span>Approve the request. The CLI picks it up instantly.</span></li>\n          </ol>\n          <form className=\"hb-qh9-token\" noValidate onSubmit={handleToken}>\n            <label className=\"hb-qh9-tlabel\" htmlFor={`${uid}-t`}>Headless machine? Paste a token instead</label>\n            <div className=\"hb-qh9-trow\">\n              <input id={`${uid}-t`} className=\"hb-qh9-tinput\" type=\"password\" autoComplete=\"off\" spellCheck={false} placeholder={`${tokenPrefix}••••••••••••••••••••`} value={token} aria-invalid={tokenError ? true : undefined} aria-describedby={tokenError ? `${uid}-te` : undefined} onChange={(e) => { setToken(e.target.value); if (tokenError) setTokenError(\"\"); }} />\n              <button type=\"submit\" className=\"hb-qh9-tbtn\" disabled={tokenBusy} aria-busy={tokenBusy}>{tokenBusy ? \"Checking\" : \"Use token\"}</button>\n            </div>\n            {tokenError && <p className=\"hb-qh9-terr\" id={`${uid}-te`} role=\"alert\">{tokenError}</p>}\n            {current === \"approved\" && !tokenError && token && <p className=\"hb-qh9-tok\" role=\"status\">Token accepted.</p>}\n          </form>\n        </div>\n        <div className=\"hb-qh9-win\">\n          <div className=\"hb-qh9-bar\">\n            <span className=\"hb-qh9-light\" aria-hidden=\"true\" />\n            <span className=\"hb-qh9-light\" aria-hidden=\"true\" />\n            <span className=\"hb-qh9-light\" aria-hidden=\"true\" />\n            <span className=\"hb-qh9-wtitle\">zsh · ~/code/northwind</span>\n          </div>\n          <div className=\"hb-qh9-body\" role=\"log\" aria-live=\"polite\">\n            <span className=\"hb-qh9-line\" style={lineStyle(0.2, l1)}><span className=\"hb-qh9-pr\">$</span> {command}</span>\n            <span className=\"hb-qh9-line\" style={lineStyle(1.1, l2)}><span className=\"hb-qh9-q\">?</span> How would you like to authenticate? <span className=\"hb-qh9-pr\">Login with a web browser</span></span>\n            <span className=\"hb-qh9-line\" style={lineStyle(2.1, \"! First copy your one-time code:\")}><span className=\"hb-qh9-warn\">!</span> First copy your one-time code:</span>\n            <div className=\"hb-qh9-codebox\" style={{ \"--hb-qh9-delay\": \"2.6s\" } as React.CSSProperties}>\n              <span className=\"hb-qh9-code\" aria-label={`One-time code ${code.split(\"\").join(\" \")}`}>{code}</span>\n              <button type=\"button\" className=\"hb-qh9-copy\" data-copied={copied} onClick={copy}>\n                {copied ? (\n                  <svg width=\"12\" height=\"12\" viewBox=\"0 0 12 12\" aria-hidden=\"true\"><path d=\"m2.5 6.2 2.3 2.3 4.7-5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" /></svg>\n                ) : (\n                  <svg width=\"12\" height=\"12\" viewBox=\"0 0 12 12\" aria-hidden=\"true\"><rect x=\"3.5\" y=\"3.5\" width=\"7\" height=\"7\" rx=\"1.5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.2\" /><path d=\"M8.5 3.5V2.5a1 1 0 0 0-1-1h-5a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1h1\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.2\" /></svg>\n                )}\n                {copied ? \"Copied\" : \"Copy\"}\n              </button>\n            </div>\n            <span className=\"hb-qh9-line\" style={lineStyle(3.1, l4)}><span className=\"hb-qh9-dim\">-</span> Press <span className=\"hb-qh9-q\">Enter</span> to open <a className=\"hb-qh9-url\" href={verifyUrl}>{host}</a> in your browser...</span>\n            {current === \"waiting\" && (\n              <span className=\"hb-qh9-wait\" style={{ \"--hb-qh9-delay\": \"4s\" } as React.CSSProperties}>\n                <span className=\"hb-qh9-spinner\" aria-hidden=\"true\" />\n                <span className=\"hb-qh9-pulse\">Waiting for approval in your browser</span>\n                <span className=\"hb-qh9-exp\">expires in {format(left)}</span>\n              </span>\n            )}\n            {current === \"approved\" && (\n              <>\n                <span className=\"hb-qh9-res\"><span className=\"hb-qh9-ok\">✓</span> Authentication complete.</span>\n                <span className=\"hb-qh9-res\"><span className=\"hb-qh9-ok\">✓</span> Logged in as <b>{user}</b></span>\n                <span className=\"hb-qh9-res\"><span className=\"hb-qh9-dim\">  token saved to ~/.config/forge/hosts.yml</span></span>\n                <span className=\"hb-qh9-res\"><span className=\"hb-qh9-pr\">$</span> <span className=\"hb-qh9-cursor\" aria-hidden=\"true\" /></span>\n              </>\n            )}\n            {current === \"expired\" && (\n              <>\n                <span className=\"hb-qh9-res\"><span className=\"hb-qh9-bad\">✗</span> The code expired before it was approved.</span>\n                <span className=\"hb-qh9-res\"><span className=\"hb-qh9-dim\">  run</span> {command} <span className=\"hb-qh9-dim\">again to get a new one</span></span>\n                <span className=\"hb-qh9-res\"><span className=\"hb-qh9-pr\">$</span> <span className=\"hb-qh9-cursor\" aria-hidden=\"true\" /></span>\n              </>\n            )}\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}