TwoFactorSetup

Two steps in one card: scan the code or copy the key, then type the digits from the app. Wrong digits shake the cells with the reason, the right ones finish with a shield. Auth.

Open playground
1. Scan with your authenticator app
Your QR code renders here
2. Enter the 6-digit code

About

TwoFactorSetup is a React component in the Auth category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { TwoFactorSetup } from "@ashutoshswamy/smoui" and set qr, secret, onVerify among its 4 props.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { TwoFactorSetup } from "@ashutoshswamy/smoui";

<TwoFactorSetup qr={<QRCodeSVG value={otpauthUrl} size={144} />} secret="JBSWY3DPEHPK3PXP" onVerify={(code) => api.verifyTotp(code)} />

Props 4

qr

The QR code. Render it with your own QR library.

ReactNode
secret

The same secret as text, shown in groups of four behind a toggle.

string
onVerify

Resolve when the code is right. Throw an Error to show its message.

(code: string) => void | Promise
length

Digits in the code.

numberdefault 6