Skip to main content
Urbicon UI
source

TwoFactorManagerbeta

Self-service two-factor (TOTP) management: enrol with an authenticator app, show one-time backup codes, and disable with a password re-auth. The core stays zero-dependency, so QR rendering is delegated to the `qr` snippet — without it the otpauth URI + Base32 secret are shown for manual entry.

01 Usage

Basic

The live preview runs against a mocked demo API (injected via the fetcher prop) — setup returns a demo secret + URI and any 6-digit code reveals demo backup codes (no real verification). The qr snippet is omitted here, so the zero-dep manual-entry fallback is shown. The snippet shows the production setup.

Two-factor authentication

Add a second step to sign-in using an authenticator app.

<script lang="ts">
  import { TwoFactorManager } from '@urbicon-ui/auth';
  import type { AuthUser } from '@urbicon-ui/auth';

  // `user` typically comes from your auth store or `locals.user`.
  let { user }: { user: AuthUser | null } = $props();
</script>

<TwoFactorManager {user} apiPath="/api/auth/account/2fa" />

02 Accessibility

The error region outlives the step it came from

The aria-live="polite" region sits directly under the heading, above the idle/setup/backup branch — not inside it. An error raised while confirming a code is therefore still announced after the view changes, which a region nested in the branch would have destroyed before the reader got to it.

The secret and the backup codes are real elements

The TOTP secret renders in a <code> element and the backup codes in a <ul> of <li>. A reader announces the list with its item count and can step through the codes one at a time — the same content as a styled grid of divs would be an unnavigable run of characters.

Autofill hints on both entry paths

Disabling 2FA re-authenticates with an autoComplete="current-password" field; the setup code uses inputmode="numeric" with autoComplete="one-time-code", which brings up the numeric keypad and lets the OS offer the code directly.

Step changes are neither focused nor announced

Moving from idle to setup to backup codes replaces the content in place, and nothing marks it: focus is not moved, and the live region above carries only errors — a successful step change clears the error first, so the region is empty exactly when the view swaps. A screen-reader user is left on a page whose content silently became something else. Move focus to the new step yourself if this flow matters to you. The QR code is a consumer-supplied snippet, so its alternative text is yours to provide; the secret is always available as text next to it for anyone who cannot scan.

03 API Reference

11 props 1 required
Prop
Type
Default
Description

04 Types

Local type definitions used by this component.

6 types
Name
Kind
Category
Used by
Description

05 Installation

Import

import { TwoFactorManager } from '@urbicon-ui/auth';