VerifyCode

One-time code check. The cells lock while it is checked, a wrong code shakes and clears for another go, a right one turns into a drawn tick. Resend sits on a visible countdown. Auth.

Open playground

Enter the 6-digit code sent to m***@smoui.dev

The right code is 123456.

About

VerifyCode 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 { VerifyCode } from "@ashutoshswamy/smoui" and set onVerify, onResend, length among its 5 props.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

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

<VerifyCode
  sentTo="m***@mail.com"
  onVerify={(code) => api.verify(code)} // return false or throw to reject
  onResend={() => api.resend()}
/>

Props 5

onVerify

Check the code. Return false or throw to reject.

(code: string) => boolean | void | Promise<boolean | void>
onResend

Called when a new code is requested.

() => void | Promise<unknown>
length

Digits.

numberdefault 6
sentTo

Where the code went, for the caption.

string
resendSeconds

Seconds before Resend unlocks.

numberdefault 30