suiss/ui ยท Block
Verify Code
A two-factor authentication screen with a six-digit code entry, error feedback, and a resend countdown.
Verify Code is an open-source block from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
A two-factor screen with a six-digit code field that turns red on a wrong code and green on success, plus a resend countdown and a help link. A wrong code shakes the field and clears it. Use it for 2FA, phone verification or any one-time code step.
Replace the comparison with DEMO_CODE in complete with your verification API, and remove the demo code hint. Resend only restarts the 30-second timer, so connect it to your code delivery service. Point #help at your support page.
The code field receives focus on load, and errors are announced.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
- Install the following dependencies:
-
Add the pieces it builds on: Input OTP.
-
Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Web preview
An InputOTP with six slots checks the code when the last digit is entered; a wrong code shakes the input and shows an error, and a correct one shows a verified screen. A resend link counts down from 30 seconds, and a help link sits below.
onVerify receives the code and returns a boolean or a promise; by default it accepts the demo code 482913. onHelp handles the help link.
Installation
The CLI also adds what it builds on: Icon, Input OTP, Keyboard Scroll View, Screen, Text. It also adds the animated view components/ui/animated-view.tsx.
- Install the following dependencies:
-
Add the pieces it builds on: Icon, Input OTP, Keyboard Scroll View, Screen, Text.
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy and paste the following code into
components/blocks/verify-code.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Add the pieces it builds on: Icon, Input OTP, Keyboard Scroll View, Screen, Text.
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy and paste the following code into
components/blocks/verify-code.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Add the pieces it builds on: Icon, Input OTP, Keyboard Scroll View, Screen, Text.
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy and paste the following code into
components/blocks/verify-code.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
onVerify receives the code and returns whether it is right, and can be async; by default it accepts the demo code 482913. onHelp handles the help link.
onVerify receives the code and returns whether it is right, and can suspend; by default it accepts the demo code 482913. onHelp handles the help link.