shadcn.io is not affiliated with official shadcn/ui
Two-Factor Methods Account Block for React
An account's two-factor methods as rows with their role, history and a Test that opens a code field in place, Make primary, a guarded Remove, and a Set up that opens a QR code, a key name or a number.
Installation
Overview
Show people which second steps protect their account, and let them prove each one still works, with this two-factor panel for React with Base UI. A compact header holds the title, a sentence that counts the methods and the one Shine Button, Add a method. Inside a hairline frame with a plus mark on each corner, three rows list an authenticator app, a security key and text messages. Each has an icon, an outline Badge with its role in words (Primary, Backup or Not set up), when it was added and last used, and how its last test went. Test opens a code field in the row with an Input OTP, says in the row which code to type in this demo and, on the sixth digit, marks the row "Worked on" the day. Make primary swaps the roles; Remove is refused for the only method and otherwise opens an Alert Dialog. A method that isn't set up has a Set up that opens its own field: a QR Code and a setup key with a Copy Button for the app, a name for a key, a number for text. The last band says what the set amounts to ("Two methods is the safest set") and reports each result. It's built from Input OTP, QR Code, Copy Button, Alert Dialog, Field, Input, Badge, Button, Shine Button and Guides, with a CSS entrance only. For the security page of any app.
FAQ
How do I fill it with my own methods?
Edit METHODS at the top: each has an id, a name, a role (primary, backup or off), the days it was added, last used and tested (ISO, empty when never), and a detail such as a key's name or the last four digits of a number. TESTS holds, for each method, what to do and the six digits that pass in this demo; ABOUT is the line a method that isn't set up shows. The count in the header, the band at the foot and the badges are all worked out from the roles, so they stay true as methods change.
How does Test work, and what stays local?
Test opens the row's code field with focus in it and says which code to type ("In this demo the code is 482 913"): a real server would never print it, but a demo that couldn't be passed would prove nothing. On the sixth digit the code is checked; a match closes the field, marks the row "Worked on 14 Oct" and says so in the status line, and a miss says what happened and keeps the digits so they can be fixed. Nothing is sent or stored. In your app, post the code to your server in typeCode and write the day it returns.
Why can't I remove the last method?
A person with two-factor on and no method could never sign in again, so the Remove button of the only method is marked aria-disabled and the row says "Your only method, so it can't be removed." The button keeps its place and focus. With two or more, Remove opens an alert dialog (no outside click closes it, Escape and Keep it do); removing the primary method promotes the other one, and the row turns to Not set up with its Set up button, which takes focus. The trigger is passed to AlertDialogTrigger through render.
What do Set up and Add a method do?
Add a method opens the first method that isn't set up (and says so when all three are). Set up opens that row's field: a made-up QR code and setup key for the app (copy it with the button; it opens nothing), a name for a key, a number with its country code for text, with the problem shown under the field and focus kept in it. Adding makes the row a Backup, or the Primary when there was none, and says that nothing was registered or sent. Enrolment proper, with a real secret and a verification step, belongs to your sign-in flow.
Is it accessible?
The rows are a list named for them. Roles and test results are words and icons, never colour. Test and Set up say whether their field is open with aria-expanded and move focus into it; closing it returns focus to the button. The code field is named by its question and described by the demo code and the problem, and the QR code has a text alternative next to the key it holds. The status line is polite and present from the start. The code field is the Input OTP built on a single input and takes one string, kept to digits by the handler.
How does it look on a phone?
Each row keeps its icon, name, role and history, with its buttons dropping under them; an open field takes the row's full width, and the QR code sits above the key. The sentence about the set and the foot's status share one line whose space is reserved, so a result never moves the rows.
Related
- Pro
Backup Codes Account
Sign-in methodsAn account's backup codes: ten one-time codes in a hairline grid with the spent ones struck through, a meter of how many are left, a real text file to download and copy, and a new set behind a password.
- Pro
Passkeys Account
Sign-in methodsAn account's passkeys: a ruled list of what each one is, when it was created and last used, a name you edit in place, a guarded Remove, and a dialog from the header that names a new passkey.
- Pro
Trusted Devices Account
Sessions and devicesAn account's trusted devices as a table of devices against two switches, one to skip the sign-in code and one to skip the password prompt, with a sentence on what each device's choice means and a meter against the limit.
- Pro
Recovery Options Account
Sign-in methodsAn account's recovery options: four numbered ways back in, each with its state in words, a masked value, a quiet test and a one-field form to set it up, and a line that counts how many are ready.
- Pro
Two-Factor Authenticator Login
Codes and approvalsA split sign-in step for an investing app: a six-digit code field beside a demo authenticator whose code and draining ring change every 30 seconds, where the current code and the one before it both sign in.
- Pro
Two-Step Setup Dialog
Account and securityA cloud editor's security page with a three-step dialog shown open: a QR code and its key, eight backup codes to copy or download, and a six-digit check, ending in a note that two-step sign-in is on.