shadcn.io is not affiliated with official shadcn/ui
OTP Verification Login Block for React
A code step for a parcel locker app: a six-digit field that checks itself on the sixth digit or on a paste, counts wrong codes down from three, and a resend button that waits 30 seconds after it is pressed.
Installation
Overview
Check a one-time code the moment it is complete, with this OTP verification login block for React with Base UI. It's the code step of a Hatchloft sign-in, a parcel locker app: the page's side rails run the full height of the screen and one band crosses it between two rules, holding a centred column. The heading says which number the text went to, and a six-digit Input OTP takes the code. The sixth digit, typed or pasted, checks it at once, with no button to press first. A wrong code clears the field, says what it cost ("Not that code. 2 tries left.") and keeps focus in the field; the third wrong one uses the code up, locks the field and moves focus to the resend button. A Countdown Button sends the next demo code and then waits 30 seconds, starting when it is pressed. The demo code is printed once under the field. It's built from Input OTP, Countdown Button, Field, Button, Shine Button and Guides, with a CSS entrance only. For sign-ins, verifications and any step that sends a short code.
FAQ
What stays in the page, and what is the demo code?
Everything. The first code is 482913, printed under the field. A resend brings 706125, then 351840 and 917264, and the list starts again. Checking waits half a second, then "You're signed in" replaces the form in the same space, with a polite status message saying nothing was sent and no session was kept. In a product, send the code from your server, limit how often it can be asked for, and check it there too: the page only holds a short typed list.
Does it really check by itself?
Yes: on the sixth digit, whether typed one key at a time or pasted whole. The Verify button and Enter do the same thing, which is why they name an incomplete code ("Enter all 6 digits.") instead of doing nothing. A wrong code is cleared when it is refused, so the next try starts from an empty field, and anything that isn't a digit is dropped.
How do paste and autofill work?
What does a wrong code cost?
A code allows three tries: "Not that code. 2 tries left.", then "1 try left.", then "That code is used up. Send a new one." and the field is locked until a new code is sent, which gives three tries again. In a product the count belongs on your server, per code and per account, since a page can't be trusted to keep it.
How does the resend wait work?
Pressing it sends the next demo code and starts a 30-second wait: the label counts down ("Wait 30s"), presses are ignored but focus stays on the button, and a fill drains behind the label. The wait starts when it is pressed, not when the page opens, so anyone can reach the button. With reduced motion the fill is hidden and the count stays as text.
Related
- 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
Verify Identity Code Delivery Login
Codes and approvalsA verification step that asks where the code should go (text message, email or authenticator app), swaps to the code field once it is sent, and counts a limit of three codes an hour down with every send.
- Pro
Recovery Email Confirmation Login
Recovery and resetA recovery step for a casual game that shows the address on file masked and asks for the full address before it sends a code, then takes the six-digit code, with a helpdesk note for anyone without access.
- Pro
Step Verification Accordion Login
Step by stepA sign-in for a clinic as an accordion of three sections: finishing one folds it to a one-line summary with a check and opens the next, sections after the open one are locked but reachable, and Edit reopens a finished one.
- Pro
PIN Keypad Dialog
Account and securityA mobile wallet's transfer review with its PIN dialog shown open: four masked slots over a keypad of twelve keys, typed digits and keypad presses writing the same value, and a fourth digit that approves.
- Pro
Device Approval Login
Codes and approvalsA sign-in screen with a drawn phone: it asks whether the request is you, shows three number buttons, approves the matching one, denies a wrong one and points Deny to a password change.